private void ListBoxLocations_SelectedIndexChanged(object sender, EventArgs e) { LandDA landDA = new LandDA(); Location location = (Location)ListBoxLocations.SelectedItem; List <Land> lands = landDA.GetLandsByLocation(location); DataGridViewLands.Rows.Clear(); int i = 0; while (i < lands.Count) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(DataGridViewLands); row.Cells[0].Value = Helper.GetNepaliNumber(i + 1); row.Cells[1].Value = lands[i].LandLocation.LocationPreviousVDC; row.Cells[2].Value = lands[i].PlotNumber; row.Cells[3].Value = lands[i].LandArea; // Store land_id as Tag row.Tag = lands[i].LandID.ToString(); DataGridViewLands.Rows.Add(row); i++; } // Update total number of lands in selected location (label text) LabelTotalLandsInSelectedLocation.Text = $"जम्मा जग्गा (कित्ता) संख्या : {Helper.GetNepaliNumber(lands.Count)}"; }
private void PopulateDGVLands() { LandDA landDA = new LandDA(); List <Land> lands = landDA.GetLands(); DataGridViewLands.Rows.Clear(); int i = 0; while (i < lands.Count) { DataGridViewRow row = new DataGridViewRow(); row.CreateCells(DataGridViewLands); row.Cells[0].Value = Helper.GetNepaliNumber(i + 1); row.Cells[1].Value = lands[i].LandLocation.LocationPreviousVDC; row.Cells[2].Value = lands[i].PlotNumber; row.Cells[3].Value = lands[i].LandArea; // Store land_id as Tag row.Tag = lands[i].LandID.ToString(); DataGridViewLands.Rows.Add(row); i++; } }
private void ButtonDeleteLand_Click(object sender, EventArgs e) { LandDA landDA = new LandDA(); DataGridViewRow selectedRow = DataGridViewLands.CurrentRow; int landID = int.Parse(selectedRow.Tag.ToString()); // Proceed only if the land has no lease if (!landDA.DoesLandHaveLease(landID)) { DialogResult dlgResult; ConfirmationForm confirmForm = new ConfirmationForm(); confirmForm.ConfirmationText = "के तपाई जग्गाको विवरण मेटाउन चाहनु हुन्छ ?"; dlgResult = confirmForm.ShowDialog(); if (dlgResult == DialogResult.OK) { MessageForm messageForm; bool result = false; Land landToDelete = new Land(); landToDelete.LandID = landID; try { result = landDA.DeleteLand(landToDelete); } catch (Exception) { messageForm = new MessageForm(); messageForm.MessageText = "आन्तरिक त्रुटीको कारण कार्य सम्पन्न गर्न सकिएन।"; messageForm.ShowDialog(); } if (result) { messageForm = new MessageForm(); messageForm.MessageText = "छनौट गरिएको जग्गाको विवरण सफलतापूर्वक मेटाइयो।"; messageForm.ShowDialog(); // Refresh the datagridview PopulateDGVLands(); } } } }
private void ButtonSave_Click(object sender, EventArgs e) { // Check if the land is duplicate LandDA landDA = new LandDA(); MessageForm messageForm; Land newLand = new Land(); newLand.LandLocation = (Location)ComboBoxLocation.SelectedItem; newLand.PlotNumber = TextBoxPlotNumber.Text; newLand.LandArea = TextBoxLandArea.Text; bool result = false; if (!landDA.IsDuplicateLand(newLand)) { try { result = landDA.SaveLand(newLand); } catch (Exception) { messageForm = new MessageForm(); messageForm.MessageText = "ओहो! केही आन्तरिक त्रुटीको कारण नयाँ जग्गाको विवरण सुरक्षित गर्न सकिएन।"; messageForm.ShowDialog(); } if (result) { messageForm = new MessageForm(); messageForm.MessageText = "नयाँ जग्गाको विवरण सफलतापूर्वक सुरक्षित गरियो।"; messageForm.ShowDialog(); } // Clear fields for new entry ClearFields(); } else { messageForm = new MessageForm(); messageForm.MessageText = "उक्त जग्गाको विवरण पहिले नै सुरक्षित गरिसकेको छ।"; messageForm.ShowDialog(); } }
private void ComboBoxLocation_SelectedIndexChanged(object sender, EventArgs e) { LandDA landDA = new LandDA(); Location location = (Location)ComboBoxLocation.SelectedItem; List <Land> lands = landDA.GetLandsByLocation(location); try { ComboBoxLand.DataSource = lands; ComboBoxLand.DisplayMember = "LandInfo"; ComboBoxLand.ValueMember = "LandID"; } catch (Exception) { MessageForm messageForm = new MessageForm(); messageForm.MessageText = "ओहो! केही आन्तरिक त्रुटीको कारण जग्गा कित्ताको विवरण लोड गर्न सकिएन।"; messageForm.ShowDialog(); } }