private void button2_Click(object sender, EventArgs e) { try { Int32 selectedRowCount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected); Int32 selectedRowIndex = dataGridView1.CurrentCell.RowIndex; if (selectedRowCount > 1) { MessageBox.Show("You have selected multiple rows. Please select a single row!"); } else { DataAccess access = new DataAccess(); String sql = "select * from admin where id = " + Convert.ToInt32(dtGLobal.Rows[selectedRowIndex][0]) + ";"; access.SqlCmd = new SqlCommand(sql, access.SqlCon); DataTable dtlocal1 = new DataTable(); access.SqlCmd.Connection.Open(); dtlocal1.Load(access.SqlCmd.ExecuteReader()); access.SqlCmd.Connection.Close(); //MessageBox.Show(Convert.ToString(dt.Rows[selectedRowIndex][3])); UpdatePassword UP = new UpdatePassword(); UP.setIDandName(Convert.ToString(dtlocal1.Rows[0][0]), Convert.ToString(dtlocal1.Rows[0][1])); UP.StartPosition = FormStartPosition.CenterParent; UP.ShowDialog(); } } catch (NullReferenceException NRE) { string errorLog = NRE.ToString(); MessageBox.Show("You have not selected any user!"); } }
/// <summary> /// Attempt to capture and resolve a color configuration object from a text configuration file. /// </summary> /// <param name="key"></param> /// <returns></returns> public Color get_color_from_config(string key) { //string value = get_setting(key); // so many internal references. //KnownColor z = new SystemColor(value); // We'll just return the color combination that will represent the .... string value = get_setting(key); int a = 0; int r = 0; int g = 0; int b = 0; try { a = int.Parse(get_setting(key + "_alpha")); // that should do it. r = int.Parse(get_setting(key + "_red")); g = int.Parse(get_setting(key + "_green")); b = int.Parse(get_setting(key + "_blue")); /* * // IF IT'S WRITING HEX - WE'LL SIMPLIFY HERE. * a = int.Parse(value.Substring(0, 2), System.Globalization.NumberStyles.HexNumber); // that should do it. * r = int.Parse(value.Substring(2, 2), System.Globalization.NumberStyles.HexNumber); * g = int.Parse(value.Substring(4, 2), System.Globalization.NumberStyles.HexNumber); * b = int.Parse(value.Substring(6, 2), System.Globalization.NumberStyles.HexNumber); */ } catch (FormatException FEX) { Console.WriteLine("Incorrect Color format - we'll reset this."); store_user_config(new Tuple <string, string>(key + "_alpha", "255")); store_user_config(new Tuple <string, string>(key + "_red", r.ToString())); store_user_config(new Tuple <string, string>(key + "_green", g.ToString())); store_user_config(new Tuple <string, string>(key + "_blue", b.ToString())); } catch (ArgumentException ARE) { Console.WriteLine("You get a zero..."); } catch (NullReferenceException NRE) { Console.WriteLine(NRE.ToString()); } //return new Tuple<int, int, int>(0, 0, 0); // just storing the data. return(Color.FromArgb(r, g, b)); }
public void readCollection(string fileName) { fileName = createExistingFileName(fileName); try { using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read)) { using (StreamReader streamReader = new StreamReader(fileStream, System.Text.Encoding.UTF8)) { string fileLine; //string[] args = new string[2]; try { while ((fileLine = streamReader.ReadLine()) != null) { string[] args = fileLine.Split('|'); cardList.AddLast(new Card(args[0], args[1])); } } catch (NullReferenceException NRE) { MessageBox.Show("There was a null reference exception. " + NRE.ToString(), "Null Reference Exception", MessageBoxButtons.OK, MessageBoxIcon.Error); } streamReader.Close(); } } } catch (DirectoryNotFoundException d) { MessageBox.Show("Directory for '" + fileName + "' was not found.", "Directory not found exception.", MessageBoxButtons.OK, MessageBoxIcon.Error); } catch (FileNotFoundException f) { MessageBox.Show("File '" + fileName + "' does not exist.", "File not found exception.", MessageBoxButtons.OK, MessageBoxIcon.Error); } }