public Transaction Transfer(BaseClient destClient, decimal sum, CURRENCY cur) { var originalSum = sum; if (sum <= 0 || !Enabled || !destClient.Enabled) { throw new ArgumentException("Incorrect sum or account is disabled!"); } if (this.Currency != cur) { sum = AznRate.Convert(sum, cur, this.Currency); } var charge = sum * this.Charge; sum += charge; if (Balance >= sum) { this.Balance -= sum; } else { throw new ArgumentException("Insufficient funds!"); } return(new TransferTran(this.UserID, originalSum, sum, this.Account, destClient.Account, charge, cur, this.Currency, DateTime.Now, true)); }
private List <CURRENCY> MapCURRENCY(DataTable dt) { List <CURRENCY> rs = new List <CURRENCY>(); for (int i = 0; i < dt.Rows.Count; i++) { CURRENCY obj = new CURRENCY(); if (dt.Columns.Contains("Currency_ID")) { obj.Currency_ID = dt.Rows[i]["Currency_ID"].ToString(); } if (dt.Columns.Contains("CurrencyName")) { obj.CurrencyName = dt.Rows[i]["CurrencyName"].ToString(); } if (dt.Columns.Contains("Exchange")) { obj.Exchange = double.Parse(dt.Rows[i]["Exchange"].ToString()); } if (dt.Columns.Contains("Active")) { obj.Active = bool.Parse(dt.Rows[i]["Active"].ToString()); } rs.Add(obj); } return(rs); }
public double Convert(CURRENCY toCurrency) { //First, convert currency to euro as we have the conversion rate for it double convertedToEuro = this.Amount; if (this.Currency != CURRENCY.EURO) { if (this.Currency == CURRENCY.USDOLLARS) { convertedToEuro = Amount / OneEuroToUSD; } else if (this.Currency == CURRENCY.YEN) { convertedToEuro = Amount / OneEuroToYen; } } //Now, convert that to the chosen currency if (toCurrency == CURRENCY.EURO) { return convertedToEuro; } else if (toCurrency == CURRENCY.USDOLLARS) { return convertedToEuro * OneEuroToUSD; } else if (toCurrency == CURRENCY.YEN) { return convertedToEuro * OneEuroToYen; } return 0.0; }
static public decimal Convert(decimal sum, CURRENCY current, CURRENCY finalCurrency) { if (current == finalCurrency) { return(sum); } if (current == CURRENCY.EUR) { sum *= EUR; } else if (current == CURRENCY.USD) { sum *= USD; } if (finalCurrency == CURRENCY.EUR) { return(sum / EUR); } if (finalCurrency == CURRENCY.USD) { return(sum / USD); } return(sum); }
public void Load_Data(CURRENCY objcurrentcy) { this.objcurrentcy = objcurrentcy; txtMaTyGia.Text = objcurrentcy.Currency_ID; txtTenTG.Text = objcurrentcy.CurrencyName; calcEdit1.Text = objcurrentcy.Exchange.ToString(); checkactive.Checked = objcurrentcy.Active; }
public ActionResult DeleteConfirmed(short id) { CURRENCY currency = db.CURRENCies.Find(id); db.CURRENCies.Remove(currency); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Withdraw(string acc, decimal sum, CURRENCY cur) { try { var client = FindClient(acc); _transactions.Add(client.Withdraw(sum, cur)); } catch (Exception e) { throw e; } }
public void Execute() { try { // Activating new campaigns int?campaignsActivated = ApplicationContext.Current.Campaigns.ActivateActualCampaigns(); if (campaignsActivated.HasValue && campaignsActivated.Value != 0) { log("Activated " + campaignsActivated.Value + " campaigns."); } else { log("No deactivated campaigns starting today were found."); } // Deactivating past campaigns int?campaignsDeactivated = ApplicationContext.Current.Campaigns.DeactivatePastCampaigns(); if (campaignsDeactivated.HasValue && campaignsDeactivated.Value != 0) { log("Deactivated " + campaignsDeactivated.Value + " past campaigns."); } else { log("No active campaigns ending today were found."); } // updating currency CurrencyConverter.CurrencyConvertorSoapClient currencyClient = new CurrencyConverter.CurrencyConvertorSoapClient("CurrencyConvertorSoap12"); double rate = currencyClient.ConversionRate(CurrencyConverter.Currency.EUR, CurrencyConverter.Currency.ALL); CURRENCY curr = new CURRENCY() { Date = DateTime.Today.Date, CurrencyRate = (decimal)rate }; CURRENCY saved = ApplicationContext.Current.Payments.GetLastConversionRate(); if (saved.Date != DateTime.Today.Date) { ApplicationContext.Current.Payments.InsertConversionRate(curr); } else { saved.CurrencyRate = curr.CurrencyRate; ApplicationContext.Current.Payments.UpdateConversionRate(saved); } } catch (Exception ex) { if (ex.InnerException == null) { log(ex.Message); } else { log(ex.Message + "\n Inner: " + ex.InnerException.Message); } } }
public ActionResult Edit(CURRENCY currency) { if (ModelState.IsValid) { db.Entry(currency).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(currency)); }
public Currency(CURRENCY entity) { if (entity == null) { return; } Id = entity.ID; Code = entity.CODE; Sign = entity.SIGN; }
public CURRENCY GetLastRate() { CURRENCY last = Context.CURRENCY.Where(c => c.Date == DateTime.Today.Date).FirstOrDefault(); if (last == null) { last = Context.CURRENCY.OrderByDescending(c => c.Date).ToList().FirstOrDefault(); } return(last); }
// // GET: /Currency/Delete/5 public ActionResult Delete(short id = 0) { CURRENCY currency = db.CURRENCies.Find(id); if (currency == null) { return(HttpNotFound()); } return(View(currency)); }
public ActionResult Create(CURRENCY currency) { if (ModelState.IsValid) { db.CURRENCies.Add(currency); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(currency)); }
public Transaction(long id, decimal amount, decimal totalAmount, long account, decimal charge, CURRENCY currency, CURRENCY totalCur, DateTime time, bool success) { _charge = charge; _success = success; _userId = id; _amount = amount; _totalAmount = totalAmount; this.account = account; _currency = currency; _totalCur = totalCur; _time = time; }
private void barLargeButtonItem2_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (gridView1.FocusedRowHandle >= 0) { string id = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, gridView1.Columns[0]).ToString(); //MessageBox.Show(id); CURRENCY objcurrentcy = new CURRENCY(); objcurrentcy = new CURRENCYController().CURRENCY_Get(id); frmCapNhatTyGia frm = new frmCapNhatTyGia(); frm.Load_Data(objcurrentcy); frm.ShowDialog(); } }
public void Transfer(string fromAcc, string toAcc, decimal sum, CURRENCY cur) { if (fromAcc == toAcc) { throw new ArgumentException("Can not be transferred to the same account!"); } try { var from = FindClient(fromAcc); var to = FindClient(toAcc); _transactions.Add(from.Transfer(to, sum, cur)); _transactions.Add(to.Deposit(sum, cur)); } catch (Exception e) { throw e; } }
static public CURRENCY StringToCurrency(string cur) { CURRENCY Cur = CURRENCY.AZN; if (cur == "USD") { Cur = CURRENCY.USD; } else if (cur == "EUR") { Cur = CURRENCY.EUR; } return(Cur); }
public Transaction Deposit(decimal sum, CURRENCY cur) { var originalSum = sum; if (sum <= 0 || !Enabled) { throw new ArgumentException("Incorrect sum or account is disabled!"); } if (this.Currency != cur) { sum = AznRate.Convert(sum, cur, this.Currency); } this.Balance += sum; return(new DepositTrans(this.UserID, originalSum, sum, this.Account, 0, cur, this.Currency, DateTime.Now, true)); }
public BaseClient(string name, string surname, int age, string phone, string mail, CURRENCY currency, bool enabled, decimal balance) { Name = name; Surname = surname; Age = age; Phone = phone; Mail = mail; Currency = currency; Enabled = enabled; UserID = 0; Account = 0; if (balance > 0) { Deposit(balance, currency); } }
public async Task <Rank> purchaseRankIdAsync(string userId, string rankId, CURRENCY currency) { var rank = await getByIdAsync(rankId); var userRanks = await _userRanksRepository.getByUserIdAsync(userId); if (userRanks.Contains(rank.id)) { throw new ShopException("This rank is already owned"); } if (currency == CURRENCY.REAL) { var money = await _moneyRepository.getMoneyByUserIdAsync(userId); var afterPurchaseMoney = money - rank.priceEuro; if (afterPurchaseMoney >= 0) { await _userRanksRepository.addAsync(userId, rankId); await _moneyRepository.createOrUpdateMoneyAsync(userId, afterPurchaseMoney); return(rank); } } else { var stats = await _statsRepository.getByUserIdAsync(userId); stats.creativity -= rank.priceCreativity; stats.fluency -= rank.priceFluency; stats.intelligence -= rank.priceIntelligence; stats.strength -= rank.priceStrength; if (stats.creativity >= 0 && stats.fluency >= 0 && stats.intelligence >= 0 && stats.strength >= 0) { await _userRanksRepository.addAsync(userId, rankId); await _statsRepository.updateAsync(stats.id.ToString(), stats); return(rank); } } throw new ShopException("There is no enough resources on your account"); }
public int CURRENCY_Insert(CURRENCY obj) { try { return(DataProvider.ExecuteNonquery(DataProvider.ConnectionString, "CURRENCY_Insert", obj.Currency_ID, obj.CurrencyName, obj.Exchange, obj.Active )); } catch { //throw ex; return(-1); } }
/// <summary> /// 增加货币单位 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddCurr_Click(object sender, EventArgs e) { if (!checkInputOfCurrency()) { MessageBox.Show("请检查输入项"); return; } using (TAXDBDataContext db = new TAXDBDataContext()) { //db.Connection.ConnectionString = Cryptogram.DecryptPassword(System.Configuration.ConfigurationManager.AppSettings["ConnectionString"].ToString()); CURRENCY curr = new CURRENCY { C_ADDTIME = DateTime.Now, C_NAME = txtCurrency.Text.Trim(), C_UIID = SysUtil.CurrentUserID(), C_ISDEL = false }; db.CURRENCies.InsertOnSubmit(curr); db.SubmitChanges(); loadCurrency(); MessageBox.Show("添加成功"); } }
private void btnAdd_Click(object sender, EventArgs e) { CURRENCY cur = EnumConverter.StringToCurrency(cbCurrency.Text); ClientMembership member = ClientMembership.Normal; switch (cbMember.Text) { case "Gold": member = ClientMembership.Gold; break; case "Platinum": member = ClientMembership.Platinum; break; } int age; int.TryParse(tbAge.Text, out age); decimal.TryParse(tbSetBalance.Text, out decimal blnc); try { _bank.AddNewClient(tbName.Text, tbSurname.Text, age, tbPhone.Text, tbMail.Text, cur, chkbEnabled.Checked, member, blnc); _bank.SaveClients(); MessageBox.Show("Client Added!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information); pnlRegistration.Visible = false; pnlAccountProp.Visible = false; } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void InsertConversionRate(CURRENCY Entity) { _currencyDAO.Insert(Entity); Context.SaveChanges(); }
public GoldenClient(string name, string surname, int age, string phone, string mail, CURRENCY currency, bool enabled, decimal balance) : base(name, surname, age, phone, mail, currency, enabled, balance) { base.Charge = 0.02m; }
public Money(double amount, CURRENCY currency) : this() { this.Amount = amount; this.Currency = currency; }
public TransferTran(long id, decimal amount, decimal totalAmount, long account, long transferTo, decimal charge, CURRENCY currency, CURRENCY totalCur, DateTime time, bool success) : base(id, amount, totalAmount, account, charge, currency, totalCur, time, success) { _transferTo = transferTo.ToString(); _type = TransactionType.Transfer; }
public WithdrawTran(long id, decimal amount, decimal totalAmount, long account, decimal charge, CURRENCY currency, CURRENCY totalCur, DateTime time, bool success) : base(id, amount, totalAmount, account, charge, currency, totalCur, time, success) { _type = TransactionType.Withdraw; }
private void CheckUserRegData(string name, string surname, int age, string phone, string mail, ClientMembership membership, CURRENCY currency) { Regex[] regex = new Regex[6]; regex[0] = new Regex(@"^[A-z]{1,30}$"); regex[1] = new Regex(@"^[+]994[55|50|51|70|77]{2}[0-9]{7}$"); regex[2] = new Regex("^[_a-z0-9-]+(.[a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$", RegexOptions.IgnoreCase); regex[3] = new Regex(@"^[AZN|USD|EUR]{3}$"); regex[4] = new Regex(@"^[Gold|Normal|Platinum]{4,8}$"); if (!regex[0].IsMatch(name)) { throw new ArgumentException("Wrong name!"); } if (!regex[0].IsMatch(surname)) { throw new ArgumentException("Wrong surname!"); } if (!(Convert.ToInt32(age) > 18 && Convert.ToInt32(age) < 100)) { throw new ArgumentException("Wrong age!"); } if (!regex[2].IsMatch(mail)) { throw new ArgumentException("Wrong mail!"); } if (!regex[1].IsMatch(phone)) { throw new ArgumentException("Wrong phone!"); } if (!regex[3].IsMatch(currency.ToString())) { throw new ArgumentException("Wrong currency!"); } if (!regex[4].IsMatch(membership.ToString())) { throw new ArgumentException("Wrong membership!"); } }
public void Delete(CURRENCY Entity) { throw new NotImplementedException(); }
public void UpdateConversionRate(CURRENCY Entity) { _currencyDAO.Update(Entity); Context.SaveChanges(); }
public void AddNewClient(string name, string surname, int age, string phone, string mail, CURRENCY currency, bool enabled, ClientMembership membership, decimal balance = 0) { mail = mail.ToLower(); try { CheckUserRegData(name, surname, age, phone, mail, membership, currency); } catch (Exception e) { throw e; } if (membership == ClientMembership.Platinum) { _clients.Add(new PlatinumClient(name, surname, age, phone, mail, currency, enabled, balance)); } else if (membership == ClientMembership.Gold) { _clients.Add(new GoldenClient(name, surname, age, phone, mail, currency, enabled, balance)); } else { _clients.Add(new Client(name, surname, age, phone, mail, currency, enabled, balance)); } SetID(_clients[_clients.Count - 1]); SetAccount(_clients[_clients.Count - 1]); }