SECI  1
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Events
EditUsers.cs
Go to the documentation of this file.
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 
10 namespace SeciControls
11 {
12  public partial class EditUsers : Form
13  {
14  private DataSet _data = new DataSet();
15  public string[,] oldUsers = null;
16  public string[,] newUsers = null;
17 
18  public EditUsers()
19  {
21  }
22 
23  private void EnterUser_Load(object sender, EventArgs e)
24  {
25  if (oldUsers != null)
26  {
27  for (int i = 0; i < oldUsers.GetLength(0); ++i)
28  {
29  try
30  {
31  if (oldUsers.GetLength(1) == 2)
32  {
33  //All users
34  dgv1.Rows.Add(oldUsers[i, 0], oldUsers[i, 1], "User");
35  }
36  else
37  {
38  if (String.IsNullOrEmpty(oldUsers[i, 2]))
39  {
40  dgv1.Rows.Add(oldUsers[i, 0], oldUsers[i, 1], "User");
41  }
42  else
43  {
44  dgv1.Rows.Add(oldUsers[i, 0], oldUsers[i, 1], oldUsers[i, 2]);
45  }
46  }
47  }
48  catch
49  {
50  }
51  }
52  }
53  }
54 
55  private void btnOK_Click(object sender, EventArgs e)
56  {
57  if (checkTable())
58  {
59  newUsers = new String[dgv1.Rows.Count, 3];
60  for (int i = 0; i < dgv1.Rows.Count; ++i)
61  {
62  if (dgv1.Rows[i].Cells[0].Value != null) newUsers[i, 0] = dgv1.Rows[i].Cells[0].Value.ToString();
63  if (dgv1.Rows[i].Cells[1].Value != null) newUsers[i, 1] = dgv1.Rows[i].Cells[1].Value.ToString();
64  if (dgv1.Rows[i].Cells[2].Value != null) newUsers[i, 2] = dgv1.Rows[i].Cells[2].Value.ToString();
65  }
66 
67  DialogResult = DialogResult.OK;
68  Close();
69  }
70  }
71 
72  private Boolean checkTable()
73  {
74  int PICount = 0;
75  int ContactCount = 0;
76 
77  for (int i = 0; i < dgv1.Rows.Count; ++i)
78  {
79  if (dgv1.Rows[i].Cells[2].Value == null) continue;
80 
81  if (dgv1.Rows[i].Cells[2].Value.ToString() == "PI")
82  {
83  ++PICount;
84  }
85  else if (dgv1.Rows[i].Cells[2].Value.ToString() == "Contact")
86  {
87  ++ContactCount;
88  }
89  }
90 
91  if (ContactCount > 1 || PICount > 1)
92  {
93  MessageBox.Show("There MUST be only one contact and PI for an experiment.", "Invalid", MessageBoxButtons.OK, MessageBoxIcon.Error);
94  return false;
95  }
96 
97  return true;
98  }
99 
100  private void btnCancel_Click(object sender, EventArgs e)
101  {
102  DialogResult = DialogResult.Cancel;
103  Close();
104  }
105 
106  private void btnAdd_Click(object sender, EventArgs e)
107  {
108  dgv1.Rows.Add("", "", "User");
109  }
110 
111  private void btnDelete_Click(object sender, EventArgs e)
112  {
113  if (dgv1.SelectedRows.Count > 0)
114  {
115  dgv1.Rows.RemoveAt(dgv1.SelectedRows[0].Index);
116  }
117  }
118  }
119 }
void InitializeComponent()
Required method for Designer support - do not modify the contents of this method with the code editor...
void btnCancel_Click(object sender, EventArgs e)
Definition: EditUsers.cs:100
Boolean checkTable()
Definition: EditUsers.cs:72
System.Windows.Forms.DataGridView dgv1
void btnDelete_Click(object sender, EventArgs e)
Definition: EditUsers.cs:111
void btnOK_Click(object sender, EventArgs e)
Definition: EditUsers.cs:55
void EnterUser_Load(object sender, EventArgs e)
Definition: EditUsers.cs:23
void btnAdd_Click(object sender, EventArgs e)
Definition: EditUsers.cs:106