Example #1
0
        private void ButtonAddNewYear_Click(object sender, EventArgs e)
        {
            try
            {
                // Get the topmost year in the listbox
                RentYear lastYear = (RentYear)ListBoxCurrentYear.Items[0];

                // Pass it to helper function and get the next higher year
                string npYear = lastYear.TheRentYear.ToString();

                RentYearDA rentYearDA  = new RentYearDA();
                RentYear   newRentYear = new RentYear();
                newRentYear.TheRentYear = Helper.GetNextYear(npYear);

                rentYearDA.SaveRentYear(newRentYear);
            }
            catch (Exception)
            {
                MessageForm messageForm = new MessageForm();
                messageForm.MessageText = "प्राविधिक कारणले गर्दा नयाँ वर्ष थप गर्न सकिएन।";
                messageForm.ShowDialog();
            }

            PopulateRentYears();
        }
Example #2
0
        public bool DeleteRentYear(RentYear rentYear)
        {
            bool result = false;

            using (SqlConnection sqlConn = new SqlConnection(GlobalConfig.ConnString()))
            {
                SqlCommand sqlCommand = new SqlCommand();
                sqlCommand.CommandType = CommandType.Text;
                sqlCommand.CommandText = "DELETE FROM RentYear WHERE year_id = @YearID";
                sqlCommand.Parameters.AddWithValue("@YearID", rentYear.YearID);

                sqlCommand.Connection = sqlConn;


                sqlConn.Open();

                int rowsAffected = sqlCommand.ExecuteNonQuery();

                if (rowsAffected > 0)
                {
                    result = true;
                }
            }

            return(result);
        }
Example #3
0
        public bool SaveRentYear(RentYear newRentYear)
        {
            bool result = false;

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

                    sqlCommand.Parameters.AddWithValue("@RentYear", newRentYear.TheRentYear);

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

                    if (rowsAffected > 0)
                    {
                        result = true;
                    }
                }
                catch (Exception)
                {
                    throw new Exception("Error: SaveRentYear() method couldn't execute properly.");
                }
            }
            return(result);
        }
Example #4
0
        private void UpdatePaymentDetails()
        {
            DataGridViewPaymentDetails.Rows.Clear();

            // Retrieve the RentYearID
            RentYear selectedRentYear = (RentYear)ComboBoxRentYear.SelectedItem;
            int      rentYearID       = selectedRentYear.YearID;

            // Retrieve records of LeasePayment for TenantID for RentYearID
            LeasePaymentDA paymentDA        = new LeasePaymentDA();
            DataTable      paymentDetailsDT = paymentDA.GetAllPaymentDetailsByRentYearID(rentYearID);

            DataGridViewPaymentDetails.Rows.Clear();

            for (int i = 0; i <= paymentDetailsDT.Rows.Count - 1; i++)
            {
                DataGridViewRow row = new DataGridViewRow();

                row.CreateCells(DataGridViewPaymentDetails);
                row.Cells[0].Value = Helper.GetNepaliNumber(i + 1);
                row.Cells[1].Value = paymentDetailsDT.Rows[i][0];
                row.Cells[2].Value = paymentDetailsDT.Rows[i][1];
                row.Cells[3].Value = paymentDetailsDT.Rows[i][2];
                row.Cells[4].Value = paymentDetailsDT.Rows[i][3];
                row.Cells[5].Value = paymentDetailsDT.Rows[i][5];
                row.Cells[6].Value = paymentDetailsDT.Rows[i][6];
                row.Cells[7].Value = paymentDetailsDT.Rows[i][7];
                row.Cells[8].Value = paymentDetailsDT.Rows[i][8];

                // Store land_id as Tag
                row.Tag = paymentDetailsDT.Rows[i][1];

                DataGridViewPaymentDetails.Rows.Add(row);
            }
        }
Example #5
0
        public bool DoesRentYearHaveLeasePayment(RentYear rentYear)
        {
            bool result = false;

            using (SqlConnection sqlConn = new SqlConnection(GlobalConfig.ConnString()))
            {
                string     sql        = "SELECT year_id FROM LeasePayment WHERE year_id = @YearID";
                SqlCommand sqlCommand = new SqlCommand(sql, sqlConn);
                sqlCommand.Parameters.AddWithValue("@YearID", rentYear.YearID);

                sqlConn.Open();
                SqlDataReader dataReader = sqlCommand.ExecuteReader();

                if (dataReader.HasRows)
                {
                    result = true;
                }
            }

            return(result);
        }
        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 #7
0
        private void ButtonDeleteYear_Click(object sender, EventArgs e)
        {
            MessageForm messageForm = new MessageForm();

            // We won't let the user delete all the years;
            // there must be at least one year in the list
            if (ListBoxCurrentYear.Items.Count > 1)
            {
                // Get the topmost year in the listbox
                RentYear selectedYear = (RentYear)ListBoxCurrentYear.Items[ListBoxCurrentYear.SelectedIndex];

                // Pass it to helper function and get the next higher year
                string npYear = selectedYear.TheRentYear.ToString();

                RentYearDA rentYearDA = new RentYearDA();

                if (rentYearDA.DoesRentYearHaveLeasePayment(selectedYear))
                {
                    messageForm.MessageText = "उक्त वर्षमा ठेक्का तिरेको रेकर्ड भएको कारणले गर्दा मेटाउन सकिएन।";
                    messageForm.ShowDialog();
                }
                else
                {
                    bool success = rentYearDA.DeleteRentYear(selectedYear);
                    if (!success)
                    {
                        messageForm.MessageText = "प्राविधिक कारणले गर्दा मेटाउन सकिएन।";
                        messageForm.ShowDialog();
                    }
                }

                PopulateRentYears();
            }
            else
            {
                messageForm.MessageText = "माफ गर्नुहोला, सूचीबाट सबै वर्ष मेटाउन सकिंदैन।";
                messageForm.ShowDialog();
            }
        }