public void DisplayRecords() { try { dataGridViewRecords.Rows.Clear(); foreach (string key in keyDictionary.Keys) { LicenseKey licenseKey = keyDictionary[key]; string[] rowArray = new string[] { licenseKey.CompanyName, licenseKey.Identifier, licenseKey.KeyString, licenseKey.DateGenerated, licenseKey.GeneratedBy }; dataGridViewRecords.Rows.Add(rowArray); } } catch (Exception ex) { MessageBox.Show("Failed to display the record.\n" + ex.Message, "recordForm:DisplayRecords", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public void WriteRecords() { try { if (!File.Exists(iniPath)) { FileStream fs = File.Create(iniPath); fs.Close(); } string tempFile = Path.GetTempFileName(); using (StreamReader sr = new StreamReader(iniPath)) { using (StreamWriter sw = new StreamWriter(tempFile)) { string line; while ((line = sr.ReadLine()) != null) { sw.WriteLine(""); } } } File.Delete(iniPath); File.Move(tempFile, iniPath); FileStream fileStream = File.Open(iniPath, FileMode.Create); using (StreamWriter sw = new StreamWriter(fileStream)) { foreach (string key in keyDictionary.Keys) { LicenseKey licenseKey = keyDictionary[key]; string strLine = licenseKey.CompanyName + splitter[0] + licenseKey.Identifier + splitter[0] + licenseKey.KeyString + splitter[0] + licenseKey.DateGenerated + splitter[0] + licenseKey.GeneratedBy; sw.WriteLine(strLine); } sw.Close(); } fileStream.Close(); } catch (Exception ex) { MessageBox.Show("Failed to write the record of the generated license keys.\n" + ex.Message, "recordForm:ReadRecords", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }