private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { int index = Convert.ToInt32(e.RowIndex); int programNum = int.Parse(dataGridView1.Rows[index].Cells[0].Value.ToString()); SearchResultsProgram f = new SearchResultsProgram(); f.Show(); this.Hide(); }
//dataGridView1_CellContentClick private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { var senderGrid = (DataGridView)sender; if (e.ColumnIndex == senderGrid.Columns["AddProgram"].Index && e.RowIndex >= 0) { int index = Convert.ToInt32(e.RowIndex); int programNum = int.Parse(dataGridView1.Rows[index].Cells[0].Value.ToString()); var ans = (from custprog in dc.customer_programs where custprog.customer_id == Program.custId && custprog.program_id == programNum select custprog).FirstOrDefault(); if (ans != null) { MessageBox.Show("מקבל השירות כבר שויך לתוכנית"); } else { MessageBox.Show(programNum.ToString()); customer_program cp = new customer_program(); //create new customer program record cp.customer_id = Program.custId; cp.program_id = programNum; cp.start_date = DateTime.Now; cp.end_date = DateTime.Parse(dataGridView1.Rows[index].Cells[5].Value.ToString()); dc.customer_programs.InsertOnSubmit(cp); dc.SubmitChanges(); } } if (e.ColumnIndex == senderGrid.Columns["MoreInfo"].Index && e.RowIndex >= 0) { int index = Convert.ToInt32(e.RowIndex); int programNum = int.Parse(dataGridView1.Rows[index].Cells[0].Value.ToString()); SearchResultsProgram f = new SearchResultsProgram(); f.Show(); this.Hide(); } }