예제 #1
0
        /// <summary>
        /// Add AccountSeriesOfNumbersRecord to database
        /// </summary>
        /// <param name="instances">AccountSeriesOfNumbersRecord instance array</param>
        /// <param name="saveAfterInsert">Save database after insertion</param>
        /// <param name="waitUntilSaving">Wait until saving</param>
        public void AccountSeriesOfNumbersRecordAdd(IEnumerable<AccountSeriesOfNumbersRecord> instances, Account account, bool saveAfterInsert = true, bool waitUntilSaving = true)
        {
            try
            {
                if (instances == null)
                    throw new ArgumentNullException("instances");
                if (account == null)
                    throw new ArgumentNullException("account");
                instances = instances.Where(i => i != null).ToArray();

                try
                {
                    foreach (var i in instances)
                        if (i.Account != account)
                            i.Account = account;

                    this.Context.AccountSeriesOfNumbersRecords.AddRange(instances);
                    if (saveAfterInsert)
                        this.SaveChanges(waitUntilSaving);
                }
                catch (Exception ex)
                {
                    var e = new Exception(ex.Message, ex);
                    for (int i = 0; i < instances.Count();i++)
                        e.Data.Add(string.Format("instance_{0}", i), instances.ElementAt(i).ToString());
                    throw e;
                }
            }
            catch (Exception ex)
            {
                Helpers.Log.Add(ex, string.Format("Repository.AccountSeriesOfNumbersRecordAdd(instances=[{0}],saveAfterInsert={1},waitUntilSaving={2})", instances == null ? "NULL" : instances.Count().ToString(), saveAfterInsert, waitUntilSaving));
                throw;
            }
        }
예제 #2
0
        /// <summary>
        /// Создание экземпляра класса
        /// </summary>
        /// <param name="account">Аккаунт</param>
        /// <param name="repository">Репозитарий</param>
        public DataCalculator(Account account, Repository repository)
        {
            if (account == null)
                throw new ArgumentNullException(nameof(account));
            if (repository == null)
                throw new ArgumentNullException(nameof(repository));

            Account = account;
            Repository = repository;

            Init();
        }
예제 #3
0
        /// <summary>
        /// Create/Get new ImportQueueRecord without any link to database
        /// </summary>
        /// <param name="ImportQueueRecordNumber">ImportQueueRecord number</param>
        /// <returns>ImportQueueRecord instance</returns>
        public ImportQueueRecord ImportQueueRecordNew(Account account = null)
        {
            try
            {
                var res = new ImportQueueRecord() 
                { 
                    ImportQueueRecordUID = Guid.NewGuid(), 
                    Account = account,
                    CreatedDate = DateTime.UtcNow,
                };

                if (account != null)
                    account.ImportQueue.Add(res);
                return res;
            }
            catch (Exception ex)
            {
                Helpers.Log.Add(ex, string.Format("Repository.ImportQueueRecordNew(account='{0}')", account == null ? "NULL" : account.ToString()));
                throw;
            }
        }
예제 #4
0
        } // ProcessArguments

        static bool ReadTransactionsIntoAccount(out Account myaccount)
        {
            var lineCount = File.ReadAllLines(strFilePath).Length;

            if (debug)
            {
                if (lineCount > 2000)
                {
                    Console.WriteLine("The input file: {0} is larger than 2000 lines and may cause problems", strFilePath);
                }
                else
                {
                    Console.WriteLine("The input file: {0} has {1} lines", strFilePath, lineCount);
                }
            }

            myaccount = new Account(lineCount);
            // Create an instance of StreamReader to read from a file.
            StreamReader sr = new StreamReader(strFilePath);

            String line;
            int numLinesInFile = 0;
            string delimStr = ",";
            char[] delimiter = delimStr.ToCharArray();
            string[] split = null;
            bool firstline = true;
            Hashtable columnmapper = new Hashtable();
            int lotIdCounter = 0;
            // Read and display lines from the file until the end of 
            // the file is reached.
            while ((line = sr.ReadLine()) != null)
            {
                numLinesInFile++;
                split = line.Split(delimiter);
                int nElmt = 0;

                SingleTransaction.eTransactionType transtype = SingleTransaction.eTransactionType.None;
                System.DateTime transdate = new DateTime();
                String stock = null;
                decimal price = 0.0M;
                decimal charges = 0.0M;
                int qty = 0;
                string lotId = null;
                try
                {
                    foreach (string s in split)
                    {
                        if (!firstline)
                        {
                            if (nElmt == Convert.ToInt32(columnmapper["Action"]))
                            {
                                if (s == "Buy")
                                    transtype = SingleTransaction.eTransactionType.Buy;
                                else if (s == "Sell")
                                    transtype = SingleTransaction.eTransactionType.Sell;
                                else if (s == "Add")
                                    transtype = SingleTransaction.eTransactionType.Add;
                                else if (s == "Remove")
                                    transtype = SingleTransaction.eTransactionType.Remove;
                                else
                                    transtype = SingleTransaction.eTransactionType.None;
                            }
                            else if (nElmt == Convert.ToInt32(columnmapper["Transaction Date"]))
                            {
                                String dtdelim = "-";
                                char[] dtdelimiter = dtdelim.ToCharArray();
                                String[] dtparts = s.Split(dtdelimiter);
                                lotId = string.Format("{0}_{1}", s, lotIdCounter++);
                                int day = Convert.ToInt32(dtparts[0]);
                                int mon = DateTime.ParseExact(dtparts[1], "MMM", CultureInfo.InvariantCulture).Month;
                                int year = Convert.ToInt32(dtparts[2]);

                                transdate = new DateTime(year, mon, day);
                            }
                            else if (nElmt == Convert.ToInt32(columnmapper["Stock Symbol"]))
                            {
                                stock = s;
                            }
                            else if (nElmt == Convert.ToInt32(columnmapper["Quantity"]))
                            {
                                qty = Convert.ToInt32(s);
                            }
                            else if (nElmt == Convert.ToInt32(columnmapper["Transaction Price"]))
                            {
                                price = Convert.ToDecimal(s);
                            }
                            else if (nElmt == Convert.ToInt32(columnmapper["Brokerage"]))
                            {
                                charges = Convert.ToDecimal(s);
                            }
                            else if (nElmt == Convert.ToInt32(columnmapper["Transaction Charges"]))
                            {
                                charges += Convert.ToDecimal(s);
                            }
                            else if (nElmt == Convert.ToInt32(columnmapper["Stamp Duty"]))
                            {
                                charges += Convert.ToDecimal(s);
                            }
                            else if (nElmt == Convert.ToInt32(columnmapper["Order Ref."]))
                            {
                                lotId = s;
                            }
                            else
                            {
                                //Console.WriteLine("-{0}-", s);
                            }
                            nElmt++;
                        }
                        else
                            columnmapper.Add(s, nElmt++);

                    }
                    if (firstline)
                    {
                        firstline = false;
                        continue;
                    }

                    if (stock != null)
                        myaccount.AddTransaction(transtype, transdate, stock, qty, price, charges, lotId);
                    else
                        Console.WriteLine("No stock code. Ignoring line: {0}", line);
                }
                catch (Exception e)
                {
                    Console.WriteLine("Caught an exception: {0} processing {1}", e.Message, line);
                }
            }
            Console.WriteLine("Read {0} lines from this file: {1}", numLinesInFile, strFilePath);
            sr.Close();
            return true;
        } // ReadTransactionsIntoAccount
예제 #5
0
 /// <summary>
 /// Add AccountSeriesOfNumbersRecord to database
 /// </summary>
 /// <param name="instance">AccountSeriesOfNumbersRecord instance</param>
 /// <param name="account">Account instance for shedule time</param>
 /// <param name="saveAfterInsert">Save database after insertion</param>
 /// <param name="waitUntilSaving">Wait until saving</param>
 public void AccountSeriesOfNumbersRecordAdd(AccountSeriesOfNumbersRecord instance, Account account, bool saveAfterInsert = true, bool waitUntilSaving = true)
 {
     AccountSeriesOfNumbersRecordAdd(new AccountSeriesOfNumbersRecord[] { instance }, account, saveAfterInsert, waitUntilSaving);
 }
예제 #6
0
 /// <summary>
 /// Create/Get new AccountSeriesOfNumbersRecord instance without any link to database
 /// </summary>
 /// <returns>AccountSeriesOfNumbersRecord instance</returns>
 public AccountSeriesOfNumbersRecord AccountSeriesOfNumbersRecordNew(Account account = null, TimeSpan? dalay = null, long? digitCount = null)
 {
     try
     {
         var res = new AccountSeriesOfNumbersRecord();
         if (dalay.HasValue)
             res.Delay = dalay.Value;
         if (digitCount.HasValue)
             res.DigitCount = digitCount.Value;
         if (account != null)
             account.SeriesOfNumbers.Add(res);
         return res;
     }
     catch(Exception ex)
     {
         Helpers.Log.Add(ex, string.Format("Repository.AccountSeriesOfNumbersRecordNew()"));
         throw;
     }
 }
예제 #7
0
 private static Expression<Func<DataRow, bool>> GetDefaultRowFilter(IEnumerable<string> columnNames, Account account)
 {
     return r => columnNames.Select(cN => r[cN] is DBNull ? (string)null : r[cN].ToString()).Any(c => string.IsNullOrWhiteSpace(c));
 }
예제 #8
0
                private static Action<DataTable> GetDefaultDataTableValidator(IEnumerable<string> columnNames, Account account)
                {
                    return (account == null)
                        ? new Action<DataTable>((t) => { })
                        : new Action<DataTable>((t) =>
                        {
                            var columns = t.Columns.OfType<DataColumn>().Select(c => c.ColumnName);

                            var notExistsedColumns = string.Empty;
                            foreach (var cn in columnNames.Where(i => !columns.Contains(i.ToString())))
                                notExistsedColumns += (string.IsNullOrWhiteSpace(notExistsedColumns)
                                    ? string.Empty
                                    : ", ") + string.Format("'{0}'", cn);

                            if (!string.IsNullOrWhiteSpace(notExistsedColumns))
                                throw new Exception(string.Format(Resources.COLUMNS_NOT_FOUND_IN_IMPORT_FILE, notExistsedColumns));
                        });
                }
예제 #9
0
파일: Phone.cs 프로젝트: kblc/Royalty
 /// <summary>
 /// Create/Get new phone without any link to database
 /// </summary>
 /// <param name="phoneNumber">Phone number</param>
 /// <param name="account">Account to add account-phone-mark instance</param>
 /// <returns>Phone instance</returns>
 public Phone PhoneNew(string phoneNumber = null, Account account = null)
 {
     try
     {
         var res = new Phone() { };
         if (phoneNumber != null)
             res.PhoneNumber = phoneNumber;
         if (account != null)
             AccountPhoneMarkNew(res, account);
         return res;
     }
     catch (Exception ex)
     {
         Helpers.Log.Add(ex, string.Format("Repository.PhoneNew(phoneNumber='{0}')", phoneNumber ?? "NULL"));
         throw;
     }
 }
예제 #10
0
        /// <summary>
        /// Create/Get new AccountPhoneMark without any link to database
        /// </summary>
        /// <param name="phone">Phone</param>
        /// <param name="account">Account</param>
        /// <param name="mark">Mark</param>
        /// <returns>AccountPhoneMark instance</returns>
        public AccountPhoneMark AccountPhoneMarkNew(Phone phone = null, Account account = null, Mark mark = null)
        {
            try
            {
                mark = mark ?? MarkGet(MarkTypes.Unknown);
                var res = new AccountPhoneMark() { Account = account, Phone = phone, Mark = mark };

                if (account != null)
                    account.PhoneMarks.Add(res);

                return res;
            }
            catch (Exception ex)
            {
                Helpers.Log.Add(ex, string.Format("Repository.AccountPhoneMarkNew(sourceId='{0}',actionType='{1}',sourceType='{2}')", phone.ToString() ?? "NULL", account.ToString() ?? "NULL", mark.ToString() ?? "NULL"));
                throw;
            }
        }
 /// <summary>
 /// Create/Get new AccountDataRecordAdditionalColumn instance without any link to database
 /// </summary>
 /// <returns>AccountDataRecordAdditionalColumn instance</returns>
 public AccountDataRecordAdditionalColumn AccountDataRecordAdditionalColumnNew(Account account = null, string columnName = null, string columnSystemName = null)
 {
     try
     {
         var res = new AccountDataRecordAdditionalColumn()
         {
             ColumnName = columnName,
             ColumnSystemName = columnSystemName,
             Account = account,
         };
         if (account != null)
             account.AdditionalColumns.Add(res);
         return res;
     }
     catch(Exception ex)
     {
         Helpers.Log.Add(ex, string.Format("Repository.AccountDataRecordAdditionalColumnNew()"));
         throw;
     }
 }