示例#1
0
        private void loansDataGridView_CellContentClick(object sender, EventArgs e)
        {
            try
            {
                var     loan  = loansDataGridView.CurrentRow;
                DL.Loan loans = (DL.Loan)loan.DataBoundItem;
                //Binding Paytime
                this.paytimesBindingSource.Filter = "LoanId=" + loans.Id;
                Employee employee = db.Employees.Find(loans.EmployeeId);
                empFullNameTextBox.Text = employee.EmpFullName;
                empIdTextBox.Text       = employee.Emp_Id.ToString();
                //badgeNumberTextBox.Text = employee.BadgeNumber;
                designationIdComboBox.SelectedText  = employee.Designation.Name;
                designationIdComboBox.SelectedValue = employee.DesignationId;

                //assign value to form
                idTextBox.Text           = loans.Id.ToString();
                amountTextBox.Text       = loans.Amount.ToString();
                installmentTextBox.Text  = loans.Installment.ToString();
                dateDateTimePicker.Value = loans.Date;
            }
            catch (Exception Ex)
            {
            }
        }
示例#2
0
        private void button5_Click(object sender, EventArgs e)
        {
            try
            {
                var     loan  = loansDataGridView.CurrentRow;
                DL.Loan loans = (DL.Loan)loan.DataBoundItem;

                //DialogBox
                var          emp = db.Employees.Find(loans.EmployeeId);
                DialogResult res = MessageBox.Show("Are you sure you want to update the loan of: " + emp.EmpFullName, "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

                if (res == DialogResult.Cancel)
                {
                    return;
                }
                //Update Loan
                DL.Loan loanU = db.Loans.Find(loans.Id);
                loanU.Installment = Convert.ToInt32(installmentTextBox.Text);
                loanU.Amount      = Convert.ToDouble(amountTextBox.Text);
                loanU.Date        = Convert.ToDateTime(dateDateTimePicker.Text);

                int id       = Convert.ToInt32(empIdTextBox.Text);
                var employee = db.Employees.FirstOrDefault(a => a.Emp_Id == id);

                loanU.EmployeeId = employee.Id;

                db.Entry(loanU).State = EntityState.Modified;
                db.SaveChanges();

                //Update Paytime

                //Delete
                List <Paytime> paytimes = db.Paytimes.Where(a => a.LoanId == loanU.Id).ToList();
                db.Paytimes.RemoveRange(paytimes);
                db.SaveChanges();

                //Save
                DateTime date = loanU.Date;
                for (int i = 1; i <= loanU.Installment; i++)
                {
                    Paytime paytime = new Paytime();
                    paytime.LoanId = loanU.Id;
                    date           = date.AddMonths(1);
                    paytime.Date   = date;
                    paytime.Amount = loanU.Amount / loanU.Installment;

                    db.Paytimes.Add(paytime);
                    db.SaveChanges();
                }

                Reload();
                MessageBox.Show("Updated Sucessfully!");
            }
            catch (Exception Ex)
            {
            }
        }
示例#3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                //Loan Data Bind
                int     empId    = Convert.ToInt32(empIdTextBox.Text);
                var     employee = db.Employees.FirstOrDefault(a => a.Emp_Id == empId);
                DL.Loan loan     = new DL.Loan();

                loan.EmployeeId  = employee.Id;
                loan.Installment = Convert.ToInt32(installmentTextBox.Text);
                loan.Date        = Convert.ToDateTime(dateDateTimePicker.Text);
                loan.Amount      = Convert.ToDouble(amountTextBox.Text);


                // Check Condition To Provide Loan

                if (loan.IsLoanHas())
                {
                    MessageBox.Show("This Employee Has Lone!");
                    return;
                }

                // Save Loan

                db.Loans.Add(loan);
                db.SaveChanges();

                // Save Paytime
                DateTime date = loan.Date;
                for (int i = 1; i <= loan.Installment; i++)
                {
                    Paytime paytime = new Paytime();
                    paytime.LoanId = loan.Id;
                    date           = date.AddMonths(1);
                    paytime.Date   = date;
                    paytime.Amount = loan.Amount / loan.Installment;

                    db.Paytimes.Add(paytime);
                    db.SaveChanges();
                }
                //Save Message
                MessageBox.Show("Save Sucessfully!");
                Reload();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.ToString());
            }
        }
示例#4
0
        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("Are you sure you want to Delete", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

            if (res == DialogResult.Cancel)
            {
                return;
            }
            var loan = loansDataGridView.CurrentRow;

            DL.Loan loans = (DL.Loan)loan.DataBoundItem;


            // Delete  Loan
            DL.Loan loanforDelete = db.Loans.Find(loans.Id);
            db.Loans.Remove(loanforDelete);
            db.SaveChanges();
            Reload();
            //Message
            MessageBox.Show("Deleted Sucessfully!");
        }