private void btn_candidate_details_Click(object sender, RoutedEventArgs e) { BallotData ballotData = ((FrameworkElement)sender).DataContext as BallotData; BallotWindow ballotWindow = new BallotWindow(ballotData); ballotWindow.ShowDialog(); }
private void btn_edit_Click(object sender, RoutedEventArgs e) { BallotData ballotData = ((FrameworkElement)sender).DataContext as BallotData; btnUpdate.IsEnabled = true; btnMasterDetails.IsEnabled = false; if (AddMasterBallot.Visibility == Visibility.Hidden) { AddMasterBallot.Visibility = Visibility.Visible; } if (ballotData != null) { ballotIdToUpdate = ballotData.BallotID; if (ballotData.constituency == "Assembly") { constituencyCombo.SelectedIndex = 1; } language2Combo.SelectedIndex = 1; string st = ballotData.state; string stt = null; string regularExpressionPattern = @"\((.*?)\)"; Regex re = new Regex(regularExpressionPattern); foreach (Match m in re.Matches(st)) { stt = m.Value; } if (stt != null) { stateCombo.SelectedValue = stt.TrimStart('(').TrimEnd(')'); } //stateCombo.SelectedValue = ballotData.state; language1Combo.SelectedValue = ballotData.language1; } }
private void dgBallotMaster_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e) //selected cell event to perform edit delete and add candidate details { //SelectedCellsChanged="dgBallotMaster_SelectedCellsChanged" in xaml string selectedColumnHeader; try { selectedColumnHeader = (string)dgBallotMaster.SelectedCells[0].Column.Header; // getting header of selected cell in datgrid } catch { return; } // var currentRowIndex = dgBallotMaster.Items.IndexOf(dgBallotMaster.CurrentItem); BallotData ballotData = (BallotData)dgBallotMaster.CurrentItem; // getting all ballot data as class object of selected row // BallotData ballotData = ((FrameworkElement)sender).DataContext as BallotData; // for button click event // code to delete record if (selectedColumnHeader == "Delete") { MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to permanently delete this record?", "Delete record", MessageBoxButton.YesNo, MessageBoxImage.Question); // MessageBoxResult messageBoxResult1 = MessageBox.Show("Are you sure you want to permanently delete this record?", "Delete record",me) if (messageBoxResult == MessageBoxResult.Yes) { int ballotId = ballotData.BallotID; deleteRow(ballotId); } else if (messageBoxResult == MessageBoxResult.No) { return; } } // code to edit record if (selectedColumnHeader == "Edit") { btnUpdate.IsEnabled = true; btnMasterDetails.IsEnabled = false; if (AddMasterBallot.Visibility == Visibility.Hidden) { AddMasterBallot.Visibility = Visibility.Visible; } ballotIdToUpdate = ballotData.BallotID; if (ballotData.constituency == "Assembly") { constituencyCombo.SelectedIndex = 1; } language2Combo.SelectedIndex = 1; stateCombo.SelectedValue = ballotData.state; language1Combo.SelectedValue = ballotData.language1; } // code to open Ballot window if (selectedColumnHeader == "Candidate Details") { BallotWindow ballotWindow = new BallotWindow(ballotData); ballotWindow.ShowDialog(); } }
private void btn_delete_Click(object sender, RoutedEventArgs e) { BallotData ballotData = ((FrameworkElement)sender).DataContext as BallotData; MessageBoxResult messageBoxResult = MessageBox.Show("Are you sure you want to permanently delete this record?", "Delete record", MessageBoxButton.YesNo, MessageBoxImage.Question); // MessageBoxResult messageBoxResult1 = MessageBox.Show("Are you sure you want to permanently delete this record?", "Delete record",me) if (messageBoxResult == MessageBoxResult.Yes) { if (ballotData != null) { int ballotId = ballotData.BallotID; deleteRow(ballotId); } } else if (messageBoxResult == MessageBoxResult.No) { return; } }
internal async Task <BatchUpdateSpreadsheetResponse> CastBallot(BallotData ballot, Election election) { // Get the current time in the time zone of the spreadsheet. var utc = DateTime.UtcNow; var tz = DateTimeZoneProviders.Tzdb[election.TimeZone]; var timeStamp = utc.ToInstant().InZone(tz).ToDateTimeUnspecified().ToCellData(); var email = ballot.Email.ToCellData(); var voterId = ballot.VoterId.ToCellData(); var voterCells = new[] { email, voterId, timeStamp }; base.BeginBatch(); AddToBatch(new Request { AppendCells = new AppendCellsRequest { SheetId = 1, Fields = "*", Rows = new[] { voterCells.ToRowData() } } }); for (var i = 0; i < election.Races.Count; i++) { var cells = new List <CellData>(); cells.Add(voterId); var scores = ballot.Races[i].Scores; foreach (var score in scores) { cells.Add(score.ToCellData()); } AddToBatch(new Request { AppendCells = new AppendCellsRequest { SheetId = election.Races[i].SheetId, Fields = "userEnteredValue", Rows = new[] { cells.ToArray().ToRowData() } } }); } var batch = EndBatch(); var response = await batch.ExecuteAsync().ConfigureAwait(false); return(response); }