private void SelectedItem(AccountView pv) { ACC_TRANSACTION ac = Acc_transactionDao.Instance().SelectbyId(pv.id); Account_tranObj = new Account_tran(ac); Account_tranLists = new ObservableCollection <Account_tran>(); Account_tranLists.Add(Account_tranObj); }
private void OKevent(Window p) { ACCOUNT ac = new ACCOUNT(); ACC_TRANSACTION tran = new ACC_TRANSACTION(); ac.AVAIL_BALANCE = AccountViewObj.avail_balance; ac.CLOSE_DATE = AccountViewObj.close_date; ac.OPEN_DATE = AccountViewObj.open_date; ac.PENDING_BALANCE = AccountViewObj.pending_balance; ac.STATUS = AccountViewObj.status; ac.PRODUCT_CD = ProductDao.Instance().SelectbyName(AccountViewObj.product).PRODUCT_CD; ac.LAST_ACTIVITY_DATE = AccountViewObj.last_date; ac.OPEN_BRANCH_ID = BranchDao.Instance().SelectbyName(AccountViewObj.branch).BRANCH_ID; ac.OPEN_EMP_ID = FindEm(AccountViewObj.NameEm, listem); ac.CUST_ID = CustId; tran.EXECUTION_BRANCH_ID = null; tran.TELLER_EMP_ID = null; tran.FUNDS_AVAIL_DATE = Account_tranObj.fund_date; tran.AMOUNT = Account_tranObj.amount; tran.TXN_DATE = Account_tranObj.txndate; tran.TXN_TYPE_CD = Account_tranObj.txntype; if (cv == "insert") { try { AccountDao.Instance().Insert(ac, tran); } catch { throw new Exception(); } } else { using (SalesEntities3 entity = new SalesEntities3()) { try { ac.ACCOUNT_ID = AccountViewObj.id; tran.ACCOUNT_ID = AccountViewObj.id; tran.TXN_ID = Account_tranObj.txnid; AccountDao.Instance().Update(ac, tran); } catch { throw new Exception(); } } } p.Close(); vm.AccountViewLists = vm.UpdateListview(); }
public Account_tran(ACC_TRANSACTION at) { if (at != null) { this.txnid = at.TXN_ID; this.amount = at.AMOUNT; this.fund_date = at.FUNDS_AVAIL_DATE; this.txndate = at.TXN_DATE; this.txntype = at.TXN_TYPE_CD; if (at.EXECUTION_BRANCH_ID != null) { this.branch = BranchDao.Instance().SelectbyId(at.EXECUTION_BRANCH_ID).NAME; } if (at.TELLER_EMP_ID != null) { this.employee = EmployeeDao.Instance().SelectbyId(at.TELLER_EMP_ID).FIRST_NAME; } } }
//Khoi tao doi tuong lam viec voi database /// <summary> /// Them mot doi tuong vao bang ACCOUNT /// </summary> /// <param name="a"> Tham so truyen vao co kieu ACCOUNT</param> public void Insert(ACCOUNT a, ACC_TRANSACTION tran) { using (SalesEntities3 entity = new SalesEntities3()) { using (var transaction = entity.Database.BeginTransaction()) { if (a != null) { try { entity.ACCOUNTs.Add(a); a.ACC_TRANSACTION.Add(tran); entity.SaveChanges(); transaction.Commit(); } catch { MessageBox.Show("Error: Insert!"); } } } } }
/// <summary> /// Cap nhat du lieu cho bang ACCOUNT /// </summary> /// <param name="a"> Tham so truyen vao co kieu ACCOUNT</param> public void Update(ACCOUNT a, ACC_TRANSACTION ac_tran) { using (SalesEntities3 entity = new SalesEntities3()) { using (var transaction = entity.Database.BeginTransaction()) { try { ACCOUNT ac = (from e in entity.ACCOUNTs where e.ACCOUNT_ID == a.ACCOUNT_ID select e).First(); ACC_TRANSACTION tran = (from e in entity.ACC_TRANSACTION where e.TXN_ID == ac_tran.TXN_ID select e).First(); ac.AVAIL_BALANCE = a.AVAIL_BALANCE; ac.CLOSE_DATE = a.CLOSE_DATE; ac.CUST_ID = a.CUST_ID; ac.LAST_ACTIVITY_DATE = a.LAST_ACTIVITY_DATE; ac.OPEN_BRANCH_ID = a.OPEN_BRANCH_ID; ac.OPEN_DATE = a.OPEN_DATE; ac.PENDING_BALANCE = a.PENDING_BALANCE; ac.STATUS = a.STATUS; ac.PRODUCT_CD = a.PRODUCT_CD; ac.OPEN_EMP_ID = a.OPEN_EMP_ID; tran.AMOUNT = ac_tran.AMOUNT; tran.EXECUTION_BRANCH_ID = ac_tran.EXECUTION_BRANCH_ID; tran.FUNDS_AVAIL_DATE = ac_tran.FUNDS_AVAIL_DATE; tran.TELLER_EMP_ID = ac_tran.TELLER_EMP_ID; tran.TXN_DATE = ac_tran.TXN_DATE; tran.TXN_TYPE_CD = ac_tran.TXN_TYPE_CD; entity.SaveChanges(); transaction.Commit(); } catch { MessageBox.Show("Error: Update!"); } } } }
private void buttonAddProduct_Click(object sender, RoutedEventArgs e)//Добавить кредит - погасить { int cust_id = -1; CUSTOMER cust = null; OFFICER offi = null; if (textBoxCost.Text.All(x => !char.IsDigit(x)) && comboBoxClientOptions.SelectedIndex != -1 && comboBoxEmployee.SelectedIndex != -1) { MessageBox.Show("Сумма введена не верно!"); return; } if (listBoxUser.SelectedItem is CUSTOMER) { cust = (CUSTOMER)listBoxUser.SelectedItem; cust_id = cust.CUST_ID; } else if (listBoxUser.SelectedItem is OFFICER) { offi = (OFFICER)listBoxUser.SelectedItem; cust_id = (int)BankView.db.OFFICER.Where(x => x.OFFICER_ID == offi.OFFICER_ID).Select(y => y.CUST_ID).FirstOrDefault(); } if (cust_id != -1) { ACCOUNT acc = new ACCOUNT(); if (buttonAddProduct.Content.ToString() == "Оформить") { acc.AVAIL_BALANCE = double.Parse(textBoxCost.Text); acc.OPEN_BRANCH_ID = bank.Select; acc.OPEN_DATE = DateTime.Now; if (comboBoxClientOptions.SelectedItem.ToString() == "Insurance Offerings") { acc.PENDING_BALANCE = double.Parse(textBoxCost.Text) * 5; } else { acc.PENDING_BALANCE = double.Parse(textBoxCost.Text); } acc.PRODUCT_CD = BankView.db.PRODUCT.Where(x => x.NAME == comboBoxClientOptions.SelectedItem.ToString()).Select(y => y.PRODUCT_CD).FirstOrDefault(); acc.CUST_ID = cust_id; acc.OPEN_EMP_ID = BankView.db.EMPLOYEE.Where(x => x.FIRST_NAME + " " + x.LAST_NAME == comboBoxEmployee.SelectedItem.ToString()).Select(y => y.EMP_ID).FirstOrDefault(); acc.STATUS = "ACTIVE"; BankView.db.ACCOUNT.InsertOnSubmit(acc); BankView.db.SubmitChanges(); comboBoxClientOptions.SelectedIndex = -1; //listBoxProductName.ItemsSource = BankView.db.ACCOUNT.Where(x => x.CUST_ID == cust_id).Select(y => y.PRODUCT.NAME); //listBoxProductName.ItemsSource = BankView.db.ACCOUNT.Where(x => x.CUST_ID == cust_id); } else if (buttonAddProduct.Content.ToString() == "Погасить/Положить") { acc = cust == null ? (ACCOUNT)listBoxProductNameVIP.SelectedItem : (ACCOUNT)listBoxProductName.SelectedItem; string product_type = BankView.db.PRODUCT.Where(x => x.PRODUCT_CD == acc.PRODUCT_CD).Select(y => y.PRODUCT_TYPE_CD).FirstOrDefault(); double pending_balance = (double)acc.PENDING_BALANCE; double cost = double.Parse(textBoxCost.Text); ACC_TRANSACTION transaction = new ACC_TRANSACTION(); transaction.ACCOUNT_ID = acc.ACCOUNT_ID; transaction.EXECUTION_BRANCH_ID = bank.Select; transaction.TELLER_EMP_ID = BankView.db.EMPLOYEE.Where(x => x.FIRST_NAME + " " + x.LAST_NAME == comboBoxEmployee.SelectedItem.ToString()).Select(y => y.EMP_ID).FirstOrDefault(); transaction.AMOUNT = cost; transaction.TXN_DATE = DateTime.Now; transaction.FUNDS_AVAIL_DATE = DateTime.Now; transaction.TXN_TYPE_CD = "CDT"; if (product_type == "ACCOUNT") //Счета { acc.PENDING_BALANCE += cost; acc.AVAIL_BALANCE += cost; BankView.db.ACC_TRANSACTION.InsertOnSubmit(transaction); BankView.db.SubmitChanges(); } else if (product_type == "LOAN") //Кредит-лизинг { if (pending_balance - cost > 0) { acc.PENDING_BALANCE -= cost; BankView.db.ACC_TRANSACTION.InsertOnSubmit(transaction); BankView.db.SubmitChanges(); } else { acc.CLOSE_DATE = DateTime.Now; acc.STATUS = "CLOSE"; BankView.db.SubmitChanges(); } } } if (cust == null) { listBoxProductNameVIP.ItemsSource = null; listBoxProductNameVIP.ItemsSource = BankView.db.ACCOUNT.Where(x => x.CUST_ID == cust_id); } else { listBoxProductName.ItemsSource = null; listBoxProductName.ItemsSource = BankView.db.ACCOUNT.Where(x => x.CUST_ID == cust_id); } } textBoxCost.Text = ""; textBoxCost.IsEnabled = false; }