private void UpdateUser(Object sender, EventArgs e) { radioSelection = RadioSelection.Update; updateCust = new UpdateCustomer(this); updateCust.UpdateCustBox.ItemsSource = custIDs; updateCust.UpdateCustBox.SelectedIndex = 0; AddUserControlStep3(updateCust); }
private void SaveFile_Button(object sender, RoutedEventArgs e) { //add new if (radioSelection == RadioSelection.Add) { if (clients.Contains(addCustID.CustomerID.Text)) { ShowDuplicateClientError(); return; } int val; if (!Int32.TryParse(addCustID.CustomerID.Text, out val)) { MessageBox.Show("Sorry, the lottery id must be a number"); return; } } Stream myStream; SaveFileDialog saveFile = new SaveFileDialog(); saveFile.Filter = "JSON Files (*.json)|*.json"; if (saveFile.ShowDialog() == true) { if ((myStream = saveFile.OpenFile()) != null) { string currEditedClientName = (updateCust == null) ? "" : updateCust.UpdateCustBox.SelectedValue.ToString(); string json = (radioSelection == RadioSelection.Translate) ? GetTranslatedFileContent() : GetEditedFileContent(currEditedClientName); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(json); myStream.Write(bytes, 0, bytes.Length); myStream.Flush(); myStream.Close(); //if they save it to a new file, open that file if (radioSelection != RadioSelection.Update) { fullPath = saveFile.FileName; currDir = Path.GetDirectoryName(fullPath); fileName = Path.GetFileNameWithoutExtension(fullPath); clients.Clear(); clients.Add(DEFAULT_CLIENT); custIDs.Clear(); ReadJsonFromFile(fullPath); PopulateClientIDs(); updateCust = new UpdateCustomer(this); updateCust.UpdateCustBox.ItemsSource = custIDs; updateCust.UpdateCustBox.SelectedIndex = 0; AddUserControlStep3(updateCust); addCustID = new AddCustomer(); AddUserControlStep3(addCustID); } if (currEditedClientName.Equals("")) { currEditedClientName = DEFAULT_CLIENT; } ReloadCurrentLottery(currEditedClientName); StkEditableValues.Children.Clear(); } //Clear Radio Buttons and user controls foreach (RadioButton child in RadioButtons.Children) { child.IsChecked = false; radioSelection = RadioSelection.Nothing; } Step3.Children.Clear(); } }