一级货位、二级货位、三级货位 根据旁边树形
foreach (TreeNode tp in tv_Place.Nodes)
{
foreach (TreeNode tn_1 in tp.Nodes)
{
if (tn_1.Nodes.Count == 0 && tn_1.Checked)
{
if (ftn_1 == false)
{
if (ftp == false)
{
temp += " ( IDT_StoreOf = '" + tp.Text + "' and ";
ftp = true;
}
else
{
temp += ") or ( IDT_StoreOf = '" + tp.Text + "' and ";
}
temp += " ( IDD_DepositedPlace like '" + tn_1.Text + "&%' ) ";
ftn_1 = true;
}
else
{
temp += " or ( IDD_DepositedPlace like '" + tn_1.Text + "&%' ) ";
}
hasplace = true;
}
else if (tn_1.Nodes.Count != 0 && tn_1.Checked)
{
bool Isall = true;
foreach(TreeNode isall in tn_1.Nodes)
{
if(isall.Checked != true)
{
Isall = false;
}
}
if(Isall ==true)
{
if (ftn_1 == false)
{
if (ftp == false)
{
temp += " ( IDT_StoreOf = '" + tp.Text + "' and ";
ftp = true;
}
else
{
temp += ") or ( IDT_StoreOf = '" + tp.Text + "' and ";
}
temp += " ( IDD_DepositedPlace like '" + tn_1.Text + "&%' ) ";
ftn_1 = true;
}
else
{
temp += " or ( IDD_DepositedPlace like '" + tn_1.Text + "&%' ) ";
}
hasplace = true;
}
else
{
foreach (TreeNode tn_2 in tn_1.Nodes)
{
if (tn_2.Nodes.Count == 0 && tn_2.Checked)
{
if (ftn_1 == false)
{
if (ftp == false)
{
temp += " ( IDT_StoreOf = '" + tp.Text + "' and ";
ftp = true;
}
else
{
temp += ") or ( IDT_StoreOf = '" + tp.Text + "' and ";
}
temp += " (IDD_DepositedPlace like '" + tn_2.Parent.Text + "&" + tn_2.Text + "&%') "; ftn_1 = true;
}
else
{
temp += " or (IDD_DepositedPlace like '" + tn_2.Parent.Text + "&" + tn_2.Text + "&%') ";
}
hasplace = true;
}
else if (tn_2.Nodes.Count != 0 && tn_2.Checked)
{
bool Isall2 = true;
foreach (TreeNode isall2c in tn_2.Nodes)
{
if (isall2c.Checked != true)
{
Isall2 = false;
}
}
if (Isall2 == true)
{
if (ftn_1 == false)
{
if (ftp == false)
{
temp += " ( IDT_StoreOf = '" + tp.Text + "' and ";
ftp = true;
}
else
{
temp += ") or ( IDT_StoreOf = '" + tp.Text + "' and ";
}
temp += " (IDD_DepositedPlace like '" + tn_2.Parent.Text + "&" + tn_2.Text + "&%') "; ftn_1 = true;
}
else
{
temp += " or (IDD_DepositedPlace like '" + tn_2.Parent.Text + "&" + tn_2.Text + "&%') ";
}
hasplace = true;
}
else
{
foreach (TreeNode tn_3 in tn_2.Nodes)
{
if (tn_3.Checked && tn_3.Nodes.Count == 0)
{
if (ftn_1 == false)
{
if (ftp == false)
{
temp += " ( IDT_StoreOf = '" + tp.Text + "' and ";
ftp = true;
}
else
{
temp += ") or ( IDT_StoreOf = '" + tp.Text + "' and ";
}
temp += " (IDD_DepositedPlace = '" + tn_3.Parent.Parent.Text + "&" + tn_3.Parent.Text + "&[" + tn_3.Text + "]' )";
ftn_1 = true;
}
else
{
temp += " or (IDD_DepositedPlace = '" + tn_3.Parent.Parent.Text + "&" + tn_3.Parent.Text + "&[" + tn_3.Text + "]' )";
}
hasplace = true;
}
}
}
}
}
}
}
}
ftn_1 = false;
}
temp += ")";
if (temp != ")" && hasplace == true)
{
temp = " and (" + temp+ ") ";
strWhere += temp;
}
TreeView不分级别加载的情况
货位信息分一、二、三级 最上级为库区信息 一共树分成四级
首先加载第一级节点 分情况(有无子节点)向下遍历 ,拼接成SQL的WHERE条件。
优化:
在一级货位遍历二级货位时,先遍历一遍下面的二级节点 如果二级节点全选的话,则条件直接为 like"一级名称&"
否则的话把二级货位全部拼接 : like"一级名称&二级名称"
同理用在二级加载三级时
这样为了节省传入的where 字符长度
1=1 and ( ( IDT_StoreOf = '本部' and ( IDD_DepositedPlace like '10L2X&%' ) or (IDD_DepositedPlace like '11L&-50新-&%') or (IDD_DepositedPlace like '11L&-55西-&%') or (IDD_DepositedPlace like '11L&-60西-&%') or (IDD_DepositedPlace like '11L&-65西-&%') or (IDD_DepositedPlace like '11L&-69西-&%') or (IDD_DepositedPlace like '11L&-东1-&%') or (IDD_DepositedPlace like '11L&-东2-&%') or (IDD_DepositedPlace like '11L&-货1-&%') or (IDD_DepositedPlace like '11L&-货2-&%') or (IDD_DepositedPlace like '11L&-西1-&%') or (IDD_DepositedPlace like '11L&-西2-&%') or (IDD_DepositedPlace like '13L&-53西-&%') or (IDD_DepositedPlace = '13L&-54西-&[10]' )))