//updates the account holder details private void UpdateButton_Click(object sender, EventArgs e) { try { dbe = new banking_dbEntities1(); decimal accountno = Convert.ToDecimal(acctxt.Text); userAccount useraccount = dbe.userAccounts.First(s => s.Account_No.Equals(accountno)); useraccount.Account_No = Convert.ToDecimal(acctxt.Text); useraccount.Name = Nametxt.Text; useraccount.Date = dateTimePicker1.Value.ToString(); useraccount.MotherName = mothertxt.Text; useraccount.FatherName = fathertxt.Text; useraccount.Phoneno = phonetxt.Text; if (maleradio.Checked == true) { useraccount.Gender = "male"; } else { if (femaleradio.Checked == true) { useraccount.Gender = "female"; } } if (marriedradio.Checked == true) { useraccount.martial_status = "married"; } else { if (unmarriedradio.Checked == true) { useraccount.martial_status = "unmarried"; } } Image img = pictureBox1.Image; if (img.RawFormat != null) { if (ms != null) { img.Save(ms, img.RawFormat); useraccount.Picture = ms.ToArray(); } } useraccount.Address = addresstxt.Text; useraccount.District = disttxt.Text; useraccount.State = statetxt.Text; dbe.SaveChanges(); MessageBox.Show("Record updated", "Record information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Exception occurred"); } }
//save new account details of the user and store to db private void SaveButton_Click(object sender, EventArgs e) { try { if (maleradio.Checked) { gender = "male"; } else if (femaleradio.Checked) { gender = "female"; } else if (otherradio.Checked) { gender = "other"; } if (marriedradio.Checked) { m_status = "married"; } else if (unmarriedradio.Checked) { m_status = "unmarried"; } BSE = new banking_dbEntities1(); userAccount acc = new userAccount(); acc.Account_No = Convert.ToDecimal(accnotext.Text); acc.Name = nametext.Text; acc.DOB = dateTimePicker1.Value.ToString(); acc.Phoneno = phonetext.Text; acc.Address = addresstext.Text; acc.District = districttext.Text; acc.State = comboBox1.SelectedItem.ToString(); acc.Gender = gender; acc.martial_status = m_status; acc.MotherName = mothertext.Text; acc.FatherName = fathertext.Text; acc.balance = Convert.ToDecimal(balancetext.Text); //acc.Date = datel acc.Picture = ms.ToArray(); BSE.userAccounts.Add(acc); BSE.SaveChanges(); //MessageBox.Show("file saved"); MessageBox.Show("File Saved", "File information", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show("Exception occurred"); } }
//deletes the details of the account private void DeleteButton_Click(object sender, EventArgs e) { try { bi.RemoveAt(UpdateGridView.SelectedRows[0].Index); dbe = new banking_dbEntities1(); decimal a = Convert.ToDecimal(acctxt.Text); userAccount acc = dbe.userAccounts.First(s => s.Account_No.Equals(a)); dbe.userAccounts.Remove(acc); dbe.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Exception occurred"); } }
//to commit the changes of transferring money from one account to the other private void TransferButton_Click(object sender, EventArgs e) { try { banking_dbEntities1 dbe = new banking_dbEntities1(); decimal b = Convert.ToDecimal(fromacctxt.Text); var item = (from u in dbe.userAccounts where u.Account_No == b select u).FirstOrDefault(); decimal b1 = Convert.ToDecimal(item.balance); decimal totalbal = Convert.ToDecimal(transfertxt.Text); decimal transferacc = Convert.ToDecimal(desaccounttxt.Text); if (b1 > totalbal) { userAccount item2 = (from u in dbe.userAccounts where u.Account_No == transferacc select u).FirstOrDefault(); item2.balance = item2.balance + totalbal; item.balance = item.balance - totalbal; //dbe.SaveChanges(); Transfer transfer = new Transfer(); transfer.Account_no = Convert.ToDecimal(fromacctxt.Text); transfer.ToTransfer = Convert.ToDecimal(desaccounttxt.Text); transfer.Date = DateTime.UtcNow.ToString(); transfer.Name = nametxt.Text; transfer.balance = Convert.ToDecimal(transfertxt.Text); dbe.Transfers.Add(transfer); dbe.SaveChanges(); //MessageBox.Show("Transfer Money Successfull"); MessageBox.Show("Transfer Money Successfull", "Money Transfer information", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Exception occurred"); } }