您的位置:首页 > 编程语言

配置实现-列表定义,编辑需自己开发的扩展实现举例(源代码)

2011-10-20 07:55 549 查看
以测试问题记录为例:

1、列表配置实现,

<?xml version="1.0" encoding="utf-8"?>

<root>

<myquery title="测试问题列表" islogicdeal="false" isfirstload="true" allowsorting="true" allowpaging="true" pagervisible="true" >

<select keycolumnnames="id" ismultiselect="false" isshowrownum="false" sortdirection="ascending">

<column name="id" title="序号" width="50px">

s_test.id

</column>

<column name="optime" title="最后更新时间" width="120px">

s_test.optime

</column>

<column name="RDate" title="发现日期" width="100px" dataformat="{0:d}">

s_test.RDate

</column>

<column name="funname" title="所属模块" width="100px">

s_fun.name

</column>

<column name="title" title="标题" width="200px">

s_test.title

</column>

<column name="notes" title="描述">

s_test.notes

</column>

<column name="IClass" title="程度" width="50px" type="select" urlformatstring="1,严重;2,次要;3,一般;4,新需求">

s_test.IClass

</column>

<column name="iflag" title="状态" width="50px" type="select" urlformatstring="0,发现;1,确认;2,解决;3,关闭">

s_test.iflag

</column>

</select>

<from type="table">

<table title="测试表">s_test</table>

<table title="菜单功能表">left join s_fun on s_test.funid=s_fun.id</table>

</from>

<where isparameter="true" isshowappend="false" issession="false">

<colgroup>

<col width="80px">

</col>

<col width="100px">

</col>

<col width="80px">

</col>

<col width="100px">

</col>

<col width="80px">

</col>

<col>

</col>

</colgroup>

<column name="iclass" title="严重程度" width="105px" type="selectint" dataformat=",全部" urlformatstring="1,严重;2,次要;3,一般;4,新需求">

and s_test.iclass={0}

</column>

<column name="funid" title="所属模块" width="105px" type="selectint" dataformat=",全部" urlformatstring="sql:select id,case when parentid>0 then ' '+name else name end from s_fun where iflag=1 order by parentid,sn">

and s_test.funid={0}

</column>

<column name="RDate" title="发生日期" cssclass="text_date" value="getweekfromtodate" type="fromtodate">

<![CDATA[and (datediff(day,{0},s_test.RDate)>=0 and datediff(day,{1},s_test.RDate)<=0)]]>

</column>

<column name="iflag" title="状态" type="selectint" dataformat=",全部" urlformatstring="0,发现;1,确认;2,解决;3,关闭">

and s_test.iflag={0}

</column>

<column name="title" title="标题" width="100px" target="all" cssclass="input_text">

and s_test.title like {0}

</column>

<column name="notes" title="描述" width="100px" target="all" cssclass="input_text">

and s_test.notes like {0}

</column>

</where>

<order>

s_test.optime desc

</order>

<buttons>

<button name="btnAdd" title="新 增" type="dialog" cssclass="input_button" windowwidth="650" windowheight="650">

Test/TestEdit.aspx

</button>

<button name="btnEdit" title="编 辑" type="dialog" cssclass="input_button" isselectedrow="true" windowwidth="650" windowheight="650">

Test/TestEdit.aspx?id={0}

</button>

<button name="toexcel" title="导出Excel" type="toexcel" cssclass="input_button">

</button>

<button name="delete" title="删 除" type="runsql" isselectedrow="true" cssclass="input_button" confirminfo="确认删除选中的记录吗?">

<sql title="选择记录删除成功">delete from S_Test where id={0}</sql>

</button>

</buttons>

</myquery>

</root>

2、编辑界面:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestEdit.aspx.cs" Inherits="MyQuery.Web.Test.TestEdit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

<title>编辑举例测试信息</title>

<script src="../Js/ClientValidate.js" type="text/javascript"></script>

<script src="../Js/calendar.js" type="text/javascript"></script>

</head>

<body>

<form id="form1" runat="server">

<div class="editblock">

<table cellpadding="0" cellspacing="0" border="0">

<colgroup>

<col width="100px" />

<col width="200px" />

<col width="100px" />

<col />

</colgroup>

<tr>

<th>

发生日期<span style="color: Red;">*</span>

</th>

<td>

<asp:TextBoxVal ID="RDate" runat="server" ClientValidate="r_date" ToolTip="请输入日期,格式:2008-08-08"></asp:TextBoxVal>

</td>

<th>

归属模块<span style="color: Red;">*</span>

</th>

<td>

<asp:DropDownList ID="FunID" runat="server">

</asp:DropDownList>

</td>

</tr>

<tr>

<th>

问题标题<span style="color: Red;">*</span>

</th>

<td colspan="3">

<asp:TextBoxVal ID="txtTitle" runat="server" MaxLength="250" Width="500px" CssClass="input_text"

ClientValidate="r_" ToolTip="请输入问题的标题"></asp:TextBoxVal>

</td>

</tr>

<tr>

<th>

问题描述 

</th>

<td colspan="3">

<asp:TextBoxVal ID="Notes" runat="server" TextMode="MultiLine" Rows="5" Width="500px"

CssClass="input_text"></asp:TextBoxVal>

</td>

</tr>

<tr>

<th>

问题截屏 

</th>

<td colspan="3">

<input id="FileName" type="file" style="width: 500px" runat="server" />

<asp:Image ID="FileImg" runat="server" Visible="false" Width="500px" ImageAlign="AbsMiddle" />

</td>

</tr>

<!--tr>

<th>

问题级别<span style="color: Red;">*</span>

</th>

<td>

<asp:DropDownList ID="IClass" runat="server">

<asp:ListItem Value="1">严重</asp:ListItem>

<asp:ListItem Value="2">次要</asp:ListItem>

<asp:ListItem Value="3">一般</asp:ListItem>

<asp:ListItem Value="4">新需求</asp:ListItem>

</asp:DropDownList>

</td>

<th>

当前状态<span style="color: Red;">*</span>

</th>

<td>

<asp:DropDownList ID="IFlag" runat="server">

<asp:ListItem Value="0">发现</asp:ListItem>

<asp:ListItem Value="1">确认</asp:ListItem>

<asp:ListItem Value="2">解决</asp:ListItem>

<asp:ListItem Value="3">关闭</asp:ListItem>

</asp:DropDownList>

</td>

</tr-->

</table>

</div>

<sy:MyInputs ID="MyInputs1" runat="server" CssClass="editblock" />

<div class="operation">

<asp:Button ID="btnAdmin" runat="server" Visible="false" Text="设计" CausesValidation="false" />

    

<asp:Button ID="btnSave" runat="server" Text="提 交" CssClass="input_button" OnClick="btnSave_Click" />

  <input type="button" value="取 消" class="input_button" onclick="window.close()" />

</div>

</form>

</body>

</html>

3、源代码

using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml;

using System.IO;

using MyQuery.Work;

using MyQuery.MyControl;

using MyQuery.Utils;

namespace MyQuery.Web.Test

{

/// <summary>

/// 编辑举例

/// 普通窗口 继承MyQuery.Work.BasePage 使用扩展则继承MyQuery.Work.BaseExpand

/// 使用扩展信息注意 1、仅支持一个表 2、不能支持验证 3、扩展字段不能和已处理的字段重复 4、需要开发人员拷贝示例代码

/// </summary>

public partial class TestEdit : MyQuery.Work.BaseExpand

{

private int id;

protected void Page_Load(object sender, EventArgs e)

{

#region 处理扩展信息 需要时完全拷贝

InitExpand(MyInputs1);

#endregion

id = DataHelper.GetIntValue(QueryString["id"], 0);

if (!Page.IsPostBack)

{

btnAdmin.Visible = "admin".Equals(CurrentUser.Id);

if (btnAdmin.Visible)

{

btnAdmin.Attributes.Add("onclick", "document.location.href='../Tmp/EditMyQuery.aspx?" + Constants.MYQUERY_NAME + "=" + name + "&t=s_test&sy=1'");

}

//控件客户端控制

WebHelper.SetControlAttributes(btnSave, new TextBoxVal[] { RDate, txtTitle });

WebHelper.SetAttributesOfFile(FileName);

//页面值初始化

dataFrom.BindListCtrl("select id,case when parentid>0 then ' '+name else name end from s_fun where iflag=1 order by cast(id as varchar),sn", FunID, false);

if (id == 0)

{

RDate.Text = System.DateTime.Today.ToString(Constants.DATE_FORMART);

}

else //当传入ID 时进行页面值初始化

{

try

{

//利用MySqlParameters 不用拼写SQL

setMySql(SqlMode.Select);

//自己给控件赋值

setControl(dataFrom.GetDataTable(mySql));

}

catch (Exception ex)

{

Logger.Error(SqlHelper.GetSql(mySql,dataFrom.Dbtype), ex);

Alert("初始化失败,请稍候再试");

}

}

}

#region 处理扩展信息 控件生成

DataBind(MyInputs1);

#endregion

}

private void setControl(DataTable dt)

{

if (dt != null && dt.Rows.Count == 1)

{

DataRow dr = dt.Rows[0];

WebHelper.SetControl(dt, RDate);

WebHelper.SetControl(dt, FunID);

txtTitle.Text = dr["title"].ToString();

WebHelper.SetControl(dt,Notes);

string fileName = dr["FileName"].ToString();

if (!String.IsNullOrEmpty(fileName))

{

FileImg.Visible = true;

FileImg.ImageUrl = "../Sys/Down.aspx?t=file&f=Test/Pimg" + id + fileName;

}

WebHelper.SetControl(dt, IClass);

WebHelper.SetControl(dt, IFlag);

#region 处理扩展信息 控件赋值

SetExpand(MyInputs1, dt);

#endregion

}

}

/// <summary>

/// 组织MySqlParameters

/// </summary>

/// <param name="sqlMode">SQL语句类别</param>

private void setMySql(SqlMode sqlMode)

{

mySql = new MySqlParameters("S_Test");

if (sqlMode == SqlMode.Select)

{

mySql.EditSqlMode = SqlMode.Select;

mySql.Add("id", id, " and id={0}");

}

else if (id == 0)

{

mySql.EditSqlMode = SqlMode.Insert;

}

else

{

mySql.EditSqlMode = SqlMode.Update;

mySql.Add("id", id, " and id={0}");

}

WebHelper.SetMySql(mySql, RDate);

WebHelper.SetMySql(mySql, FunID);

mySql.Add("title", txtTitle.Text);

WebHelper.SetMySql(mySql, Notes);

if (sqlMode == SqlMode.Select)

{

mySql.Add("FileName", null);

}

else if (!WebHelper.IsNullOrEmpty(FileName))

{

mySql.Add("FileName", getFileName(mySql.EditSqlMode));

}

WebHelper.SetMySql(mySql, IClass);

WebHelper.SetMySql(mySql, IFlag);

mySql.Add("optime", DateTime.Now);

mySql.Add("UserID", CurrentUser.Id);

#region 处理扩展信息 将字段、值 加入mySql

AddMySql(MyInputs1);

#endregion

}

private string getFileName(SqlMode sqlMode)

{

if (sqlMode == SqlMode.Select

|| String.IsNullOrEmpty(FileName.Value))

{

return "";

}

else

{

return Path.GetExtension(FileName.Value);

}

}

protected void btnSave_Click(object sender, EventArgs e)

{

if (!WebHelper.IsNullOrEmpty(FileName))

{

if (!(FileName.Value.EndsWith(".png", StringComparison.CurrentCultureIgnoreCase)

|| FileName.Value.EndsWith(".jpg", StringComparison.CurrentCultureIgnoreCase)

|| FileName.Value.EndsWith(".jpeg", StringComparison.CurrentCultureIgnoreCase)))

{

Alert("截图文件必须为png、jpg、jpeg文件", FileName.ClientID);

return;

}

}

bool isOk = true;

try

{

setMySql(SqlMode.Update);

if (id == 0)

{

mySql.IsAddGetIDSql = true;

id = DataHelper.GetIntValue(dataFrom.GetScalar(mySql), 0);

}

else

{

isOk = dataFrom.SqlExecute(mySql) == 1;

}

if (!WebHelper.IsNullOrEmpty(FileName))

{

string fileName = getFileName(mySql.EditSqlMode);

string sPath = WebHelper.GetFilePath() + "Test/"; //物理路径

if (!Directory.Exists(sPath))

{

Directory.CreateDirectory(sPath);

}

FileName.PostedFile.SaveAs(sPath + "Pimg" + id + fileName);

}

}

catch (Exception ex)

{

isOk = false;

Logger.Error(SqlHelper.GetSql(mySql,dataFrom.Dbtype), ex);

}

if (isOk)

{

Close(null);

}

else

{

Close("提交失败,请稍后再试");

}

}

}

}

4、编辑扩展的xml配置

<?xml version="1.0" encoding="utf-8"?>

<root>

<myquery title="测试编辑扩展" pagesize="0">

<select>

<colgroup>

<col style="width: 100px;" />

<col style="width: 200px;"/>

<col style="width: 100px;" />

<col />

</colgroup>

<column name="IClass" title="程度" width="105px" type="selectint" urlformatstring="1,严重;2,次要;3,一般;4,新需求">

</column>

<column name="iflag" title="状态" width="105px" type="selectint" urlformatstring="0,发现;1,确认;2,解决;3,关闭">

</column>

</select>

</myquery>

</root>

欢迎访问:http://121.18.78.216 适易查询分析、工作流、内容管理及项目管理演示平台
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐