private void ButtonSave_Click(object sender, EventArgs e)
        {
            LeasePaymentDA leasePaymentDA = new LeasePaymentDA();

            Tenant    selectedTenant = (Tenant)ComboBoxTenant.SelectedItem;
            LeaseLand leasedLand     = (LeaseLand)ComboBoxLeaseLand.SelectedItem;
            RentYear  rentYear       = (RentYear)ComboBoxRentYear.SelectedItem;

            MessageForm messageForm = new MessageForm();

            if (!leasePaymentDA.IsDuplicatePayment(leasedLand.LeaseID, rentYear.YearID))
            {
                LeasePayment newLeasePayment = new LeasePayment();
                newLeasePayment.LeaseID       = leasedLand.LeaseID;
                newLeasePayment.YearID        = rentYear.YearID;
                newLeasePayment.LeaseRent     = TextBoxAnnualRent.Text;
                newLeasePayment.PaymentDate   = TextBoxPaymentDate.Text;
                newLeasePayment.ReceiptNumber = TextBoxReceiptNumber.Text;
                newLeasePayment.Remarks       = TextBoxRemarks.Text;

                bool success = leasePaymentDA.SaveLeasePayment(newLeasePayment);

                if (success)
                {
                    messageForm.MessageText = $"उक्त जग्गाको {rentYear.TheRentYear} सालको ठेक्का बुझाएको अभिलेख सुरक्षित गरियो।";
                }
                else
                {
                    messageForm.MessageText = $"प्राविधिक कारणले गर्दा उक्त ठेक्का बुझाएको विवरण सुरक्षित गर्न सकिएन।";
                }
                messageForm.ShowDialog();
            }
            else
            {
                messageForm.MessageText = $"उक्त जग्गाको {rentYear.TheRentYear} सालको ठेक्का बुझाइसकेको छ।";
                messageForm.ShowDialog();
            }

            ClearFields();
        }
Example #2
0
        public bool SaveLeasePayment(LeasePayment leasePayment)
        {
            bool result = false;

            using (SqlConnection sqlConn = new SqlConnection(GlobalConfig.ConnString()))
            {
                try
                {
                    SqlCommand sqlCommand = new SqlCommand();
                    sqlCommand.CommandType = CommandType.StoredProcedure;
                    sqlCommand.CommandText = "SaveLeasePayment";
                    sqlCommand.Connection  = sqlConn;

                    sqlCommand.Parameters.AddWithValue("@LeaseID", leasePayment.LeaseID);
                    sqlCommand.Parameters.AddWithValue("@YearID", leasePayment.YearID);
                    sqlCommand.Parameters.AddWithValue("@LeaseRent", leasePayment.LeaseRent);
                    sqlCommand.Parameters.AddWithValue("@PaymentDate", leasePayment.PaymentDate);
                    sqlCommand.Parameters.AddWithValue("@ReceiptNumber", leasePayment.ReceiptNumber);
                    sqlCommand.Parameters.AddWithValue("@Remarks", leasePayment.Remarks);

                    sqlConn.Open();
                    int rowsAffected = sqlCommand.ExecuteNonQuery();

                    if (rowsAffected > 0)
                    {
                        result = true;
                    }
                }
                catch (Exception)
                {
                    throw new Exception("Error: SaveLeasePayment() method couldn't execute properly.");
                }
            }

            return(result);
        }