日期:2014-05-18  浏览次数:20830 次

方法中 再用此方法
C# code

        [AjaxMethod]
        public string GetGetCustInfo(string custCode)
        {
            DataTable dt = CustomerBLL.CreateInstance().CustomerList(" WHERE CustomerID='" + custCode + "' ", 1, 100);

            string strTopFatherCode = "", strTopFatherName = "", strLevelCode = "", strTopFatherID="";
            if (dt.Rows.Count > 0)
            {
                if (string.IsNullOrEmpty(dt.Rows[0]["TopFatherID"].ToString()))
                {
                    strTopFatherCode = dt.Rows[0]["CustomerCode"].ToString();
                    strTopFatherName = dt.Rows[0]["CustomerName"].ToString();
                    strTopFatherID = dt.Rows[0]["CustomerID"].ToString();
                    strLevelCode = (Convert.ToInt16(dt.Rows[0]["LevelCode"]) + 1).ToString();
                }
                else
                {
                    // 如果 TopFatherID 不为空  再走一次这个方法  该如何写
                    
                }
                

                return strTopFatherCode + "|" + strTopFatherName + "|" + strLevelCode + "|" + dt.Rows[0]["CustomerCode"].ToString() + "|" + strTopFatherID;
            }
            else
            {
                return "";
            }
        }







------解决方案--------------------
你啥问题???
------解决方案--------------------
就是个递归啊,以TopFatherID 为条件退出即可,不过TopFatherID最好作为全局或者参数,不要是局部变量
------解决方案--------------------
探讨
就是个递归啊,以TopFatherID 为条件退出即可,不过TopFatherID最好作为全局或者参数,不要是局部变量

------解决方案--------------------
[AjaxMethod]
public string state="0";
public string GetGetCustInfo(string custCode)
{
DataTable dt = CustomerBLL.CreateInstance().CustomerList(" WHERE CustomerID='" + custCode + "' ", 1, 100);

string strTopFatherCode = "", strTopFatherName = "", strLevelCode = "", strTopFatherID="";
if (dt.Rows.Count > 0)
{
if (string.IsNullOrEmpty(dt.Rows[0]["TopFatherID"].ToString()))
{
strTopFatherCode = dt.Rows[0]["CustomerCode"].ToString();
strTopFatherName = dt.Rows[0]["CustomerName"].ToString();
strTopFatherID = dt.Rows[0]["CustomerID"].ToString();
strLevelCode = (Convert.ToInt16(dt.Rows[0]["LevelCode"]) + 1).ToString();
}
else
{
if(state=="0"){GetGetCustInfo(custCode);state="1"};
else return "";
}


return strTopFatherCode + "|" + strTopFatherName + "|" + strLevelCode + "|" + dt.Rows[0]["CustomerCode"].ToString() + "|" + strTopFatherID;
}
else
{
return "";
}
}