此处的代码用于检查dataGridView(Productgridview)中添加的药物之间是否存在任何交互
数据库架构:
表产品:productId;名称
table product_druginteractionclass:productId; druginteractionclassId
表格互动:interactionId; druginteractionclassId1;
druginteractionclassId2; riskcomment
table druginteractionclass:druginteractionclassId;名称
许多产品可以具有相同的药物相互作用类别编号
方法是:
是否可以动态创建列表并循环抛出它们 做组合而不知道运行时间有多少列表?
我想在交互网格视图中循环,如果没有删除不适当的交互,请检查产品是否重复。
实际上我是药房学生(我只是喜欢编码并且做得不好,我甚至没有完成c#/ sql / ado.net之间大约600页的任何c#书,所以请原谅)
var ds2 = new DataSet();
for (var i = 0; i < Productgridview.Rows.Count; i++)
{
var listclasse = Productgridview.Rows[i].Cells["Productid"].Value.ToString();
var datadrug2 = "SELECT * FROM product_druginteractionclass" +
" where productId = '" +
listclasse + "'"; // listclasse is the list of manually added drugClass
var connection1 = new SqlCeConnection(connectionString);
var dataadapter1 = new SqlCeDataAdapter(datadrug2, connection1);
//var ds = new DataSet();
connection1.Open();
dataadapter1.Fill(ds2, "product_druginteractionclass");
connection1.Close();
}
listclassification.DataSource = ds2;
listclassification.DataMember = "product_druginteractionclass";
/////////////// put the druginteractionclass into 2 lists
var list1 = new List<string>();
var list2 = new List<string>();
foreach (DataGridViewRow item in listclassification.Rows)
if ((item.Cells.Count >= 2) && //atleast two columns
(item.Cells[1].Value != null)) //value is not null
{
list1.Add(item.Cells[1].Value.ToString());
list2.Add(item.Cells[1].Value.ToString());
}
//for (var i = 0; i <= list.Count - 1; i++)
//{
// // MessageBox.Show(list[i].ToString());
//}
//////////// select interaction based on druginteractionclass
var ds = new DataSet();
for (var i = 0; i <= list1.Count - 1; i++)
for (var j = 0; j <= list2.Count - 1; j++)
{
var value = list1[i];
var value1 = list2[j];
var datadrug3 = "SELECT u1.name, u2.name , m.* " +
"FROM druginteractionclass u1 " +
"left outer JOIN interaction m" +
" ON u1.druginteractionclassId = m.druginteractionclassId1 " +
"left outer JOIN druginteractionclass u2 " +
"ON u2.druginteractionclassId = m.druginteractionclassId2" +
" where m.druginteractionclassId1 = '" + value +
"' and m.druginteractionclassId2 ='" + value1 + "'" +
"Order by m.severity ";
var connection = new SqlCeConnection(connectionString);
var dataadapter = new SqlCeDataAdapter(datadrug3, connection);
connection.Open();
dataadapter.Fill(ds, "interaction");
connection.Close();
}
dataGridView1.DataSource = null;
dataGridView1.DataSource = ds;
dataGridView1.DataMember = "interaction";
/////// remove duplicated interactions
for (var currentRow = 0; currentRow < dataGridView1.Rows.Count - 1; currentRow++)
{
var rowToCompare = dataGridView1.Rows[currentRow];
for (var otherRow = currentRow + 1; otherRow < dataGridView1.Rows.Count; otherRow++)
{
var row = dataGridView1.Rows[otherRow];
var duplicateRow = true;
for (var cellIndex = 0; cellIndex < row.Cells.Count; cellIndex++)
if (!rowToCompare.Cells[2].Value.Equals(row.Cells[2].Value))
{
duplicateRow = false;
break;
}
if (duplicateRow)
{
dataGridView1.Rows.Remove(row);
otherRow--;
}
}
}
答案 0 :(得分:0)
>>> a = "$$$$abcd"
>>> a.count('$')
4
>>> a = '$abcd$dsf$'
>>> a.count('$')
3