public async Task <IActionResult> CreateExpenses(FinancialRecord model, string Type)
        {
            //載入下拉選單
            ResultModel SelectListresult = new ResultModel();
            Uri         targetUri        = new Uri(_config["api"] + "/FinancialItem/list/?Type=" + Type);

            SelectListresult = await _callApi.CallAPI("", targetUri, "GET");

            if (SelectListresult.IsSuccess == true && SelectListresult.Data != null)
            {
                model.FinancialItems = JsonConvert.DeserializeObject <IEnumerable <SelectListItem> >(SelectListresult.Data.ToString());
            }
            //END載入下拉選單
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var data = JsonConvert.SerializeObject(model);

            ResultModel result = new ResultModel();

            result = await _callApi.CallAPI(data, new Uri(_config["api"] + "/FinancialRecord"), "POST");

            TempData["IsSuccess"] = result.IsSuccess;
            TempData["msg"]       = result.Message;
            if (!result.IsSuccess)
            {
                return(View(model));
            }

            return(RedirectToAction(nameof(CreateExpenses), new { Type = "支出" }));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }


            ResultModel result  = new ResultModel();
            Uri         address = new Uri(_config["api"] + "/FinancialRecord/" + id.ToString());

            result = await _callApi.CallAPI("null", address, "GET");


            if (result.IsSuccess == true)
            {
                FinancialRecord r = new FinancialRecord();
                r = JsonConvert.DeserializeObject <FinancialRecord>(result.Data.ToString());
                TempData["isSuccess"] = "true";
                return(View(r));
            }
            else
            { //result.IsSuccess == false
                TempData["isSuccess"] = "false";
                TempData["msg"]       = "Record Id not exist.";
                return(View());
            }
        }
Ejemplo n.º 3
0
        public async Task <ResultModel> Delete(int id)
        {
            var             result = new ResultModel();
            FinancialRecord item   = await _context.FinancialRecords.FindAsync(id);

            if (item == null)
            {
                result.IsSuccess = false;
                result.Message   = "查無資料";
            }
            else
            {
                try
                {
                    _context.Remove(item);
                    await _context.SaveChangesAsync();

                    result.IsSuccess = true;
                    result.Message   = "刪除成功";
                }
                catch (Exception e)
                {
                    result.IsSuccess = false;
                    result.Message   = "DB error.";
                }
            }

            var accessToken = Request.Headers["Authorization"];
            var user        = await _TokenGetUserHelper.GetUser(accessToken);

            logger.Info("userId=" + user.Id + ", username="******"\n Deltete " + "FinancialRecord id= " + id + " successfully.");
            return(result);
        }
Ejemplo n.º 4
0
        private List <FinancialRecord> FinancialRecords(string username)
        {
            List <FinancialRecord> Records = new List <FinancialRecord>();

            SqlConnection sqlconn    = commonContext.connectonToMSSQL();
            string        sqlCommand = string.Format(@"use {0}; select  * from QT_Financial_Record where UserName=N'{1}' order by RecordTime DESC;", DBName, username);

            sqlconn.Open();
            SqlCommand cmd = new SqlCommand(sqlCommand, sqlconn);

            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            while (reader.Read())
            {
                FinancialRecord Record = new FinancialRecord();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    PropertyInfo property = Record.GetType().GetProperty(reader.GetName(i));
                    property.SetValue(Record, reader.IsDBNull(i) ? "[null]" : reader.GetValue(i), null);
                }
                Records.Add(Record);
            }
            reader.Close();
            return(Records);
        }
        void RandomizePrice(FinancialRecord item)
        {
            var price = GenerateNewPrice(item.Price);

            item.Change        = price.Item1 - item.Price;
            item.Price         = price.Item1;
            item.ChangePercent = price.Item2;
        }
Ejemplo n.º 6
0
        private List <FinancialRecord> GetFinancialRecordsByUsersNames(string username)
        {
            List <FinancialRecord> financialRecords = new List <FinancialRecord>();
            SqlConnection          sqlconn          = commonContext.connectonToMSSQL();

            string sqlCommand = string.Format(@"use {0};select * from QT_Financial_Record where 1=1  ", DBName);

            if (string.IsNullOrEmpty(username))
            {
            }
            else
            {
                string[] usernames = username.Split(',');

                if (usernames.Count() == 1)
                {
                    sqlCommand += string.Format(" and UserName='******'", username);
                }

                else
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("'" + usernames[0] + "'");
                    for (int i = 1; i < usernames.Count(); i++)
                    {
                        sb.Append("," + string.Format((" '{0}' "), usernames[i]));
                    }

                    sqlCommand += string.Format(" and UserName in ({0})", sb.ToString());
                }
            }

            sqlconn.Open();
            SqlCommand    cmd    = new SqlCommand(sqlCommand, sqlconn);
            SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);

            while (reader.Read())
            {
                FinancialRecord financialRecord = new FinancialRecord();
                for (int i = 0; i < reader.FieldCount; i++)
                {
                    PropertyInfo property = financialRecord.GetType().GetProperty(reader.GetName(i));
                    property.SetValue(financialRecord, reader.IsDBNull(i) ? "[null]" : reader.GetValue(i), null);
                }
                financialRecords.Add(financialRecord);
            }
            reader.Close();
            return(financialRecords);
        }
        public async Task <IActionResult> CreateExpenses(string Type)
        {
            //載入下拉選單
            ResultModel result    = new ResultModel();
            Uri         targetUri = new Uri(_config["api"] + "/FinancialItem/list/?Type=" + Type);

            result = await _callApi.CallAPI("", targetUri, "GET");

            FinancialRecord record = new FinancialRecord();

            if (result.IsSuccess == true && result.Data != null)
            {
                record.FinancialItems = JsonConvert.DeserializeObject <IEnumerable <SelectListItem> >(result.Data.ToString());
            }
            //END載入下拉選單

            return(View(record));
        }
        public async Task <IActionResult> Edit(int id, string Type)
        {
            ResultModel result  = new ResultModel();
            Uri         address = new Uri(_config["api"] + "/FinancialRecord/" + id.ToString());

            result = await _callApi.CallAPI("null", address, "GET");

            FinancialRecord f = new FinancialRecord();

            if (result.IsSuccess == true)
            {
                f = JsonConvert.DeserializeObject <FinancialRecord>(result.Data.ToString());
                if (!string.IsNullOrEmpty(f.ReturnDate))
                {
                    f.ReturnDate = f.ReturnDate.Split("T")[0];
                }

                if (!string.IsNullOrEmpty(f.DueDate))
                {
                    f.DueDate = f.DueDate.Split("T")[0];
                }
                //載入下拉選單
                ResultModel SelectListresult = new ResultModel();
                Uri         targetUri        = new Uri(_config["api"] + "/FinancialItem/list/?Type=" + Type);
                SelectListresult = await _callApi.CallAPI("", targetUri, "GET");

                if (SelectListresult.IsSuccess == true && SelectListresult.Data != null)
                {
                    f.FinancialItems = JsonConvert.DeserializeObject <IEnumerable <SelectListItem> >(SelectListresult.Data.ToString());
                }
                //END載入下拉選單
                //TempData["isSuccess"] = "true";
                return(View(f));
            }
            else
            { //result.IsSuccess == false
                TempData["isSuccess"] = "false";
                TempData["msg"]       = result.Message;
                return(View());
            }
        }
        public List <FinancialRecord> GetData(int numberOfRecords)
        {
            List <FinancialRecord> items = new List <FinancialRecord>();

            for (int i = 0; i < numberOfRecords; i++)
            {
                var rand     = new Random().Next(FinancialDataStore.FinancialDataItems.Count);
                var dataItem = FinancialDataStore.FinancialDataItems[rand];

                var region = FinancialDataStore.Regions[GenerateRandomNumber(0, 5)];

                var newFinancialRecord = new FinancialRecord()
                {
                    Category      = dataItem.Category,
                    Type          = dataItem.Type,
                    Contract      = FinancialDataStore.Contracts[GenerateRandomNumber(0, 4)],
                    Settlement    = FinancialDataStore.Settlements[GenerateRandomNumber(0, 1)],
                    Region        = region,
                    Country       = RandomizeCountry(region),
                    OpenPrice     = dataItem.OpenPrice,
                    Price         = dataItem.Price,
                    Change        = dataItem.Change,
                    ChangePercent = dataItem.ChangePercent,
                    Buy           = dataItem.Buy,
                    Sell          = dataItem.Sell,
                    Spread        = dataItem.Spread,
                    Volume        = dataItem.Spread,
                    HighD         = dataItem.HighD,
                    LowD          = dataItem.LowD,
                    HighY         = dataItem.HighY,
                    LowY          = dataItem.LowY,
                    StartY        = dataItem.StartY,
                    IndGrou       = "Airlines",
                    IndSect       = "Consumer, Cyclical",
                    IndSubg       = "Airlines",
                    SecType       = "PUBLIC",
                    IssuerN       = "AMERICAN AIRLINES GROUP",
                    Moodys        = "WR",
                    Fitch         = "N.A.",
                    DBRS          = "N.A.",
                    CollatT       = "NEW MONEY",
                    Curncy        = "USD",
                    Security      = "001765866 Pfd",
                    Sector        = "Pfd",
                    CUSIP         = 1765866,
                    Ticker        = "AAL",
                    Cpn           = 7.875,
                    Maturity      = "7/13/1939",
                    KRD_3YR       = 6E-05,
                    ZV_SPREAD     = 28.302,
                    KRD_5YR       = 0,
                    KRD_1YR       = -0.00187,
                };

                RandomizePrice(newFinancialRecord);

                items.Add(newFinancialRecord);
            }

            return(items);
        }
Ejemplo n.º 10
0
        public async Task <ResultModel> Post(FinancialRecord record)
        {
            var result             = new ResultModel();
            var existFinancialItem = _context.FinancialItems.FirstOrDefault(a => a.Id == record.FinancialItemId);

            if (record.FinancialItemId == 57 || record.FinancialItemId == 75)
            {
                //計算xx燈剩餘位子數量
                int max_Light = 666;
                if (record.Position > max_Light / 2)
                {
                    result.IsSuccess = false;
                    result.Message   = "位置最多為" + max_Light / 2;
                    return(result);
                }

                var existPosition = _context.FinancialRecords
                                    .Where(a => a.FinancialItemId == record.FinancialItemId)
                                    .Where(a => a.Position == record.Position)
                                    .Where(a => a.DueDate > DateTime.Now);
                if (existPosition.Count() > 0)
                {
                    result.IsSuccess = false;
                    result.Message   = "位置已佔用,請重新選擇";
                    return(result);
                }
            }
            try
            {
                NotifyModel notify = new NotifyModel();
                notify.CreateDate = DateTime.Now;
                notify.IsRead     = false;
                notify.ItemName   = existFinancialItem.Name;
                notify.MemberName = record.CustomerName;
                _context.Notification.Add(notify);

                record.CreateDate = DateTime.Now.ToLocalTime();

                _context.FinancialRecords.Add(record);
                result.IsSuccess = true;
                result.Message   = "添加紀錄成功.";
                await _context.SaveChangesAsync();

                result.Data = new
                {
                    Id = record.Id
                };
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Message   = "DB ERROR";
            }

            var accessToken = Request.Headers["Authorization"];
            var user        = await _TokenGetUserHelper.GetUser(accessToken);

            logger.Info("userId=" + user.Id + ", username="******"\n Create " + "FinancialRecord id= " + record.Id + " successfully.");


            return(result);
        }
Ejemplo n.º 11
0
        public async Task <ResultModel> Put([FromBody] FinancialRecordToPut item)
        {
            var             result       = new ResultModel();
            FinancialRecord itemToUpdate = await _context.FinancialRecords.FindAsync(item.Id);

            //檢查是否存在
            if (itemToUpdate == null)
            {
                result.IsSuccess = false;
                result.Message   = "查無資料.";
                return(result);
            }
            if (item.FinancialItemId != null)
            {
                var existItem = _context.FinancialItems.FirstOrDefault(a => a.Id == item.FinancialItemId);
                if (existItem == null)
                {
                    result.IsSuccess = false;
                    result.Message   = "財務項目不存在.";
                    return(result);
                }
                itemToUpdate.FinancialItemId = item.FinancialItemId;
                if (item.FinancialItemId == 57 || item.FinancialItemId == 75)
                {
                    //計算xx燈剩餘位子數量
                    int max_Light = 666;
                    if (item.Position > max_Light / 2)
                    {
                        result.IsSuccess = false;
                        result.Message   = "位置最多為" + max_Light / 2;
                        return(result);
                    }

                    var existPosition = _context.FinancialRecords
                                        .Where(a => a.FinancialItemId == item.FinancialItemId)
                                        .Where(a => a.Position == item.Position)
                                        .Where(a => a.DueDate > DateTime.Now);

                    if (existPosition.Count() > 0)
                    {
                        if (existPosition.FirstOrDefault().Id != item.Id)
                        {
                            result.IsSuccess = false;
                            result.Message   = "位置已佔用,請重新選擇";
                            return(result);
                        }
                    }
                }
            }

            if (item.Amount != null)
            {
                itemToUpdate.Amount = item.Amount;
            }

            if (item.CustomerName != null)
            {
                itemToUpdate.CustomerName = item.CustomerName;
            }
            if (item.CustomerPhone != null)
            {
                itemToUpdate.CustomerPhone = item.CustomerPhone;
            }
            if (item.LandPhone != null)
            {
                itemToUpdate.LandPhone = item.LandPhone;
            }
            if (item.DueDate != null)
            {
                itemToUpdate.DueDate = Convert.ToDateTime(item.DueDate);
            }
            if (item.FinancialItemId != null)
            {
                itemToUpdate.FinancialItemId = item.FinancialItemId;
            }
            if (item.Quantity != null)
            {
                itemToUpdate.Quantity = item.Quantity;
            }
            if (item.Notes != null)
            {
                itemToUpdate.Notes = item.Notes;
            }

            itemToUpdate.Position = item.Position;
            if (item.ReturnDate != null)
            {
                //if (item.ReturnDate != "") {
                //DateTime temp;
                //if (!DateTime.TryParse(item.ReturnDate.ToString(), out temp)) {
                //    result.IsSuccess = false;
                //    result.Message = "還願日期有誤";
                //    return result;
                //}
                //itemToUpdate.ReturnDate = item.ReturnDate;
                //}
                //if (item.ReturnDate == "")
                //itemToUpdate.ReturnDate = "";
                itemToUpdate.ReturnDate = Convert.ToDateTime(item.ReturnDate);
            }


            itemToUpdate.Place = item.Place;
            if (string.IsNullOrEmpty(item.Place))
            {
                itemToUpdate.DueDate = null;
            }

            if (item.PayType != null)
            {
                itemToUpdate.PayType = item.PayType;
            }
            try
            {
                result.IsSuccess = true;
                result.Message   = "編輯成功";
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                result.IsSuccess = false;
                result.Message   = "DB ERROR";
            }
            var accessToken = Request.Headers["Authorization"];
            var user        = await _TokenGetUserHelper.GetUser(accessToken);

            //logger.Info("userId=" + user.Id + ", username="******"\n Edit " + "FinancialRecord id= " + item.Id + " successfully.");

            return(result);
        }