请教如何一个将php函数转为.net方法

hnsongbiao 2014-04-13 07:12:11

function showdistrict($values, $elems=array(), $container='districtbox', $showlevel=null, $containertype = 'birth') {
$html = '';
if(!preg_match("/^[A-Za-z0-9_]+$/", $container)) {
return $html;
}
$showlevel = !empty($showlevel) ? intval($showlevel) : count($values);
$showlevel = $showlevel <= 4 ? $showlevel : 4;
$upids = array(0);
for($i=0;$i<$showlevel;$i++) {
if(!empty($values[$i])) {
$upids[] = intval($values[$i]);
} else {
for($j=$i; $j<$showlevel; $j++) {
$values[$j] = '';
}
break;
}
}
$options = array(1=>array(), 2=>array(), 3=>array(), 4=>array());
if($upids && is_array($upids)) {
foreach(C::t('common_district')->fetch_all_by_upid($upids, 'displayorder', 'ASC') as $value) {
if($value['level'] == 1 && ($value['id'] != $values[0] && ($value['usetype'] == 0 || !(($containertype == 'birth' && in_array($value['usetype'], array(1, 3))) || ($containertype != 'birth' && in_array($value['usetype'], array(2, 3))))))) {
continue;
}
$options[$value['level']][] = array($value['id'], $value['name']);
}
}
$names = array('province', 'city', 'district', 'community');
for($i=0; $i<4;$i++) {
if(!empty($elems[$i])) {
$elems[$i] = dhtmlspecialchars(preg_replace("/[^\[A-Za-z0-9_\]]/", '', $elems[$i]));
} else {
$elems[$i] = ($containertype == 'birth' ? 'birth' : 'reside').$names[$i];
}
}
for($i=0;$i<$showlevel;$i++) {
$level = $i+1;
if(!empty($options[$level])) {
$jscall = "showdistrict('$container', ['$elems[0]', '$elems[1]', '$elems[2]', '$elems[3]'], $showlevel, $level, '$containertype')";
$html .= '<select name="'.$elems[$i].'" id="'.$elems[$i].'" class="ps" onchange="'.$jscall.'" tabindex="1">';
$html .= '<option value="">'.lang('spacecp', 'district_level_'.$level).'</option>';
foreach($options[$level] as $option) {
$selected = $option[0] == $values[$i] ? ' selected="selected"' : '';
$html .= '<option did="'.$option[0].'" value="'.$option[1].'"'.$selected.'>'.$option[1].'</option>';
}
$html .= '</select>';
$html .= '  ';
}
}
return $html;
}


class table_common_district extends discuz_table
{
public function __construct() {

$this->_table = 'common_district';
$this->_pk = 'id';

parent::__construct();
}

public function fetch_all_by_upid($upid, $order = null, $sort = 'DESC') {
$upid = is_array($upid) ? array_map('intval', (array)$upid) : dintval($upid);
if($upid !== null) {
$ordersql = $order !== null && !empty($order) ? ' ORDER BY '.DB::order($order, $sort) : '';
return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('upid', $upid)." $ordersql", array($this->_table), $this->_pk);
}
return array();
}

public function fetch_all_by_name($name) {
if(!empty($name)) {
return DB::fetch_all('SELECT * FROM %t WHERE '.DB::field('name', $name), array($this->_table));
}
return array();
}

}

public function fetch_all() {
return DB::fetch_all('SELECT * FROM %t', array($this->_table));
}


...全文
78 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
hnsongbiao 2014-04-13
  • 打赏
  • 举报
回复
将showdistrict转为.net的

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧