/// <summary>
/// 前台出发事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void GetCheckBox_Click(object sender, EventArgs e)
{
CheckBox chkk = (CheckBox)sender;
DataControlFieldCell dcf = (DataControlFieldCell)chkk.Parent;
GridViewRow gvr = (GridViewRow)dcf.Parent;
int intgvr = gvr.RowIndex;
GetPreCHE(chkk, intgvr);
GetSonCHE(chkk, intgvr);
}
#region
// if (chkk.Checked)
// {
// int i = gvr.RowIndex;
// CheckBox chk = (CheckBox)gvlist.Rows[i].FindControl("CheckBox");
// ITEMCODE = gvlist.Rows[i].Cells[2].Text.ToString();
// for (int j = 0; j < (ITEMCODE.Length % 4); j++)
// {
// string itemcode = ITEMCODE.Substring(0, ITEMCODE.Length - j * 4);
// for (int z = 0; z < gvlist.Rows.Count; z++)
// {
// if (gvlist.Rows[z].Cells[2].Text.ToString() == itemcode)
// {
// CheckBox chkz = (CheckBox)gvlist.Rows[z].FindControl("CheckBox");
// chkz.Checked = true;
// }
// }
// for (int z = 0; z < gvlist.Rows.Count; z++)
// {
// if (gvlist.Rows[z].Cells[2].Text.ToString().Length > ITEMCODE.Length)
// {
// if (gvlist.Rows[z].Cells[2].Text.ToString().Substring(0, ITEMCODE.Length) == ITEMCODE)
// {
// CheckBox chkz = (CheckBox)gvlist.Rows[z].FindControl("CheckBox");
// chkz.Checked = true;
// }
// }
// }
// }
// }
//
// else
// {
// int i = gvr.RowIndex;
// CheckBox chk = (CheckBox)gvlist.Rows[i].FindControl("CheckBox");
// ITEMCODE = gvlist.Rows[i].Cells[2].Text.ToString();
// for (int z = 0; z < gvlist.Rows.Count; z++)
// {
// if (gvlist.Rows[z].Cells[2].Text.ToString().Length > ITEMCODE.Length)
// {
// if (gvlist.Rows[z].Cells[2].Text.ToString().Substring(0, ITEMCODE.Length) == ITEMCODE)
// {
// CheckBox chkz = (CheckBox)gvlist.Rows[z].FindControl("CheckBox");
// chkz.Checked = false;
// }
// }
// }
// for (int z = 0; z < gvlist.Rows.Count; z++)
// {
// int j = 1;
// if (gvlist.Rows[z].Cells[2].Text.ToString().Length == ITEMCODE.Length)
// {
// if (gvlist.Rows[z].Cells[2].Text.ToString().Substring(0, ITEMCODE.Length - 1) == ITEMCODE.Substring(0, ITEMCODE.Length))
// {
// j++;
// }
// }
// if (j == 1)
// {
// for (int b = 0; b < gvlist.Rows.Count; b++)
// {
// if (gvlist.Rows[b].Cells[2].Text.ToString().Substring(0, gvlist.Rows[b].Cells[2].Text.ToString().Length - 4) == ITEMCODE.Substring(0, ITEMCODE.Length - 4))
// {
// CheckBox chkz = (CheckBox)gvlist.Rows[z].FindControl("CheckBox");
// chkz.Checked = false;
// }
// }
// }
// }
// }
//}
#endregion
/// <summary>
/// 给父级添加或选择一下
/// </summary>
/// <param name="chkk"></param>
/// <param name="gvr"></param>
private void GetPreCHE(CheckBox chkk, int intgvr)
{
string ITEMCODE = string.Empty;
int i = intgvr;
CheckBox chk = (CheckBox)gvlist.Rows[i].FindControl("CheckBox");
ITEMCODE = gvlist.Rows[i].Cells[2].Text.ToString();
if (chkk.Checked)
{
for (int j = 0; j < gvlist.Rows.Count; j++)
{
string itemcode = ITEMCODE.Substring(0, ITEMCODE.Length - 4);
for (int z = 0; z < gvlist.Rows.Count; z++)
{
if (gvlist.Rows[z].Cells[2].Text.ToString() == itemcode)
{
CheckBox chkz = (CheckBox)gvlist.Rows[z].FindControl("CheckBox");
chkz.Checked = true;
GetPreCHE(chkk, z);
}
}
}
}
else
{
int j = 1;
for (int z = 0; z < gvlist.Rows.Count; z++)
{
if (gvlist.Rows[z].Cells[2].Text.ToString().Substring(0, gvlist.Rows[z].Cells[2].Text.Length - 1) == ITEMCODE.Substring(0, ITEMCODE.Length - 1))
{
if (gvlist.Rows[z].Cells[2].Text.ToString().Substring(0, ITEMCODE.Length - 1) == ITEMCODE.Substring(0, ITEMCODE.Length - 1))
{
CheckBox chkz = (CheckBox)gvlist.Rows[z].FindControl("CheckBox");
if (chkz.Checked == true)
{
j++;
}
}
}
}
//没有跟自己同一父级的同级
if (j == 1)
{
for (int b = 0; b < gvlist.Rows.Count; b++)
{
if (gvlist.Rows[b].Cells[2].Text.ToString() == ITEMCODE.Substring(0, ITEMCODE.Length - 4))
{
CheckBox chkz = (CheckBox)gvlist.Rows[b].FindControl("CheckBox");
chkz.Checked = false;
GetPreCHE(chkk, b);
}
}
}
}
}
/// <summary>
/// 给子集添加或选择一下
/// </summary>
/// <param name="chkk"></param>
/// <param name="gvr"></param>
private void GetSonCHE(CheckBox chkk, int intgvr)
{
string ITEMCODE = string.Empty;
int i = intgvr;
CheckBox chk = (CheckBox)gvlist.Rows[i].FindControl("CheckBox");
ITEMCODE = gvlist.Rows[i].Cells[2].Text.ToString();
if (chkk.Checked)
{
for (int z = 0; z < gvlist.Rows.Count; z++)
{
if (gvlist.Rows[z].Cells[2].Text.ToString().Length > ITEMCODE.Length)
{
if (gvlist.Rows[z].Cells[2].Text.ToString().Substring(0, ITEMCODE.Length) == ITEMCODE)
{
CheckBox chkz = (CheckBox)gvlist.Rows[z].FindControl("CheckBox");
chkz.Checked = true;
GetSonCHE(chkk, z);
}
}
}
}
else
{
int j = 1;
//判断是否有子集
for (int z = 0; z < gvlist.Rows.Count; z++)
{
if (gvlist.Rows[z].Cells[2].Text.ToString().Length == ITEMCODE.Length + 4)
{
if (gvlist.Rows[z].Cells[2].Text.ToString().Substring(0, gvlist.Rows[z].Cells[2].Text.Length - 4) == ITEMCODE)
{
CheckBox chkz = (CheckBox)gvlist.Rows[z].FindControl("CheckBox");
chkz.Checked = false;
GetSonCHE(chkk, z);
}
}
}
}
}