private void bSave_Click(object sender, EventArgs e)
 {
     ContractRepository crep = new ContractRepository();
     Contract contract = crep.getContract(contractId);
     PaymentRepository repository = new PaymentRepository();
     PersianDateFormatter pdf = new PersianDateFormatter();
     Payment payment = new Payment();
     payment.ContractId = contractId;
     payment.AmountOfPayment = Convert.ToInt32(tPayment.Text);
     payment.DateOfPayment = pdf.convert(tPaymentDate.Text);
     DateModel dm = pdf.getSplittedDateIntegers(payment.DateOfPayment.Value);
     payment.Year = dm.Year;
     payment.Month = dm.Month;
     payment.Day = dm.Day;
     contract.Payment += payment.AmountOfPayment;
     repository.addPayment(payment);
     crep.updateContract(contract);
 }
 private void radGridView2_UserDeletingRow(object sender, GridViewRowCancelEventArgs e)
 {
     //payment
     DialogResult result = MessageBox.Show("آیا از عملیات حذف مطمئن هستید؟", "هشدار", MessageBoxButtons.YesNo);
     if (result == DialogResult.No)
     {
         e.Cancel = true;
     }
     else
     {
         ContractRepository repository = new ContractRepository();
         PaymentRepository pRepo = new PaymentRepository();
         int paymentAmount = Convert.ToInt32(radGridView2.SelectedRows[0].Cells[1].Value.ToString());
         int paymentId = Convert.ToInt32(radGridView2.SelectedRows[0].Cells[0].Value.ToString());
         Contract contract = repository.getContract(selectedContractId);
         contract.Payment -= paymentAmount;
         pRepo.deletePayment(paymentId);
         repository.updateContract(contract);
         radGridView1.DataSource = repository.getContractsByCustomerId(customerId).ToList();
     }
 }
        private void CustomerInfoForm_Load(object sender, EventArgs e)
        {
            PersianDateFormatter pdf = new PersianDateFormatter();
            CustomerRepository repository = new CustomerRepository();
            Customer customer = repository.getCustomer(customerId);
            lName.Text = customer.FirstName + " " + customer.LastName;
            lPhoneNumber.Text = "شماره تماس:" + "   " + customer.PhoneNumber;
            lCreatedDate.Text = "تاریخ ایجاد:" + "   " + pdf.convert(customer.CreatedDate.Value);
            if (String.IsNullOrWhiteSpace(customer.Description))
            {
                lDescription.Text = "توضیحات:" + "   " + "-";
            }
            else
            {
                lDescription.Text = "توضیحات:" + "   " + customer.Description;
            }
            ContractRepository crepository = new ContractRepository();
            radGridView1.DataSource = crepository.getContractsByCustomerId(customerId).ToList();

            ((GridTableElement)radGridView1.TableElement).AlternatingRowColor = Color.FromArgb(215, 234, 124);
            radGridView1.TableElement.RowHeight = 25;
            ((GridTableElement)radGridView2.TableElement).AlternatingRowColor = Color.FromArgb(255, 205, 139);
            radGridView2.TableElement.RowHeight = 25;
            ((GridTableElement)radGridView3.TableElement).AlternatingRowColor = Color.FromArgb(240, 240, 240);
            radGridView3.TableElement.RowHeight = 25;

            if (radGridView1.SelectedRows.Count > 0)
            {
                //MessageBox.Show(radGridView1.SelectedRows[0].Cells[0].Value.ToString());
                PaymentRepository paymentRepository = new PaymentRepository();
                AppointmentRepository appointmentRepository = new AppointmentRepository();
                selectedContractId = Convert.ToInt32(radGridView1.SelectedRows[0].Cells[0].Value.ToString());
                radGridView2.DataSource = paymentRepository.getPaymentsByContractId(selectedContractId).ToList();
                radGridView3.DataSource = appointmentRepository.getAppointmentByContractId(selectedContractId).ToList();
            }

            if (radGridView1.SelectedRows.Count < 1)
            {
                bNewAppointment.Enabled = false;
                bNewPayment.Enabled = false;
            }
        }
 private void radGridView1_SelectionChanged(object sender, EventArgs e)
 {
     //MessageBox.Show(radGridView1.SelectedRows[0].Cells[0].Value.ToString());
     PaymentRepository paymentRepository = new PaymentRepository();
     AppointmentRepository appointmentRepository = new AppointmentRepository();
     selectedContractId = Convert.ToInt32(radGridView1.SelectedRows[0].Cells[0].Value.ToString());
     radGridView2.DataSource = paymentRepository.getPaymentsByContractId(selectedContractId).ToList();
     radGridView3.DataSource = appointmentRepository.getAppointmentByContractId(selectedContractId).ToList();
     bNewAppointment.Enabled = true;
     bNewPayment.Enabled = true;
 }
 private void bNewPayment_Click(object sender, EventArgs e)
 {
     AddPayment addPayment = new AddPayment(selectedContractId);
     var result = addPayment.ShowDialog();
     if (result == DialogResult.OK)
     {
         PaymentRepository paymentRepository = new PaymentRepository();
         ContractRepository repository = new ContractRepository();
         radGridView1.DataSource = repository.getContractsByCustomerId(customerId).ToList();
         radGridView2.DataSource = paymentRepository.getPaymentsByContractId(selectedContractId).ToList();
     }
 }