1、SQL问题:
MMC不能打开文件 C:\Program Files\Microsoft SQL Server\80\Tools\BINN\SQL Server Enterprise
Manager.MSC。
这可能是由于文件不存在,不是一个MMC控制台,或者用后来版本的 MMC创建。也可能是由于您没有访问此文件的足够权限。
运行:MMC
控制台根节点——>文件 添加删除管理单元->独立->添加->Microsoft SQL 企业管理器
保存一下就行了
2、
各种绑定表达式的写法
<%=Session["Msg"].ToString().Trim()%> //获取Session的值,在前台直接显示
<a href='<%=WebURL%>'>登 录</a></div>调用后台变量public string WebURL;
<label><%#Getquote_Num()%></label>//调用后台的方法
public string Getquote_Num()//后台页面方法
{
//报价
string str1 = "jl";
//年月日时分秒
string str2 = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
string str = str1 + str2;
return str;
}
//只读绑定
<asp:TemplateField HeaderText="单据编号" SortExpression="sal_rec_Num">
<ItemTemplate>
<asp:Label ID="LabelSalRecNum" runat="server" Text='<%# Eval("sal_rec_Num") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("sal_rec_Num") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
//读写绑定
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="lbtnSelect" runat="server" CausesValidation="False"
CommandName="Select" Text="查看" CommandArgument='<%# Bind("sal_rec_Num") %>'></asp:LinkButton>
<asp:LinkButton ID="lbtnEdit" runat="server" CausesValidation="False"
CommandName="Edit" Text="编辑" CommandArgument='<%# Bind("sal_rec_Num") %>'></asp:LinkButton>
<asp:LinkButton ID="lbtnDelete" runat="server" CausesValidation="False"
CommandName="Delete" Text="删除" CommandArgument='<%# Bind("sal_rec_Num") %>' OnClientClick='return confirm("是否要删除该记录?");'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
传值给后台的方法,进行逻辑判断后将值返回前台
<asp:TemplateField HeaderText="签约方" SortExpression="c_id">
<ItemTemplate>
<%--<asp:Label ID="Label2" runat="server" Text='<%# Bind("con_customerid") %>'></asp:Label>--%>
<%# GetCus_Name(DataBinder.Eval(Container, "DataItem.c_id").ToString())%>
<%-- <%# EIP.Common.StringPares.GetSubString(DataBinder.Eval(Container, "DataItem.TopicTitle").ToString(),16) %>--%>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("c_id") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
public string GetCus_Name(string cid)//后台方法
{
string strName = "无名";
if (cid != "")
{
contant con = new contant();
DataSet ds = new DataSet();
string strWhere = "1=1 and c_id=" + cid;
ds = con.GetCustomeList(strWhere);
if (ds.Tables[0].Rows.Count != 0)
{
strName = ds.Tables[0].Rows[0]["c_name"].ToString();
}
else
{
strName = "无名";
}
}
return strName;
}
3、
分页控件的习惯写法
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CR_PaiGongManager.aspx.cs" Inherits="BeidouWY.Web.CR_PaiGong.CR_PaiGongManager" %>
<!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>
<link href="/Css/CommStyle.css" rel="Stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div class="divmain">
<table width="100%">
<tr>
<td colspan="2" class="tdhead">
派工表
</td>
</tr>
<tr>
<td colspan="2">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%"
SkinID="GridView1" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:BoundField DataField="DanJuHao" HeaderText="单据号" />
<asp:BoundField DataField="NeiBuGongDanHao" HeaderText="内部工单号" />
<asp:BoundField DataField="PersonName" HeaderText="姓名" />
<asp:BoundField DataField="CompName" HeaderText="公司名称" />
<asp:BoundField DataField="Deptname" HeaderText="部门名称" />
<asp:BoundField DataField="PaiGongShiJian" HeaderText="派工时间" />
<asp:BoundField DataField="KaiGongShiJian" HeaderText="开工时间" />
<asp:BoundField DataField="WanGongShiJian" HeaderText="完工时间" />
</Columns>
<HeaderStyle CssClass="Gridheadbh" />
</asp:GridView>
<div style="float: left">
<label>共</label><asp:Label ID="lblCount" runat="server"></asp:Label>
<label>条,每页</label><asp:Label ID="lblEveryPageNum" runat="server"></asp:Label>
<label>条,共</label><asp:Label ID="lblCountPage" runat="server"></asp:Label>
<label>页,当前为第</label><asp:Label ID="lblCurrentPageNum" runat="server"></asp:Label>
<label>页</label>
</div>
<div style="float: right">
<webdiyer:AspNetPager ID="AspNetPager1" runat="server" PageSize="10" OnPageChanged="AspNetPager1_PageChanged">
</webdiyer:AspNetPager>
</div>
</td>
</tr>
<tr>
<td valign="middle">
<asp:ImageButton ID="ibtn_Add" runat="server" ImageUrl="~/Images/Add.jpg" OnClick="ibtn_Add_Click" />
<asp:ImageButton ID="ibtn_Edit" runat="server" ImageUrl="~/Images/edit.gif" OnClick="ibtn_Edit_Click" />
<asp:ImageButton ID="ibtn_Del" runat="server" ImageUrl="~/Images/Del.gif" OnClientClick='return confirm("是否要删除该记录?");'
OnClick="ibtn_Del_Click" />
<asp:ImageButton ID="ibtn_Export" runat="server" ImageUrl="~/Images/Export.gif" OnClick="ibtn_Export_Click" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
后台页面:
public static string connectionString = PubConstant.ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
GridBind();
}
}
private void asppagetitle()
{
lblCount.Text = AspNetPager1.RecordCount.ToString();
lblEveryPageNum.Text = AspNetPager1.PageSize.ToString();
lblCountPage.Text = ((AspNetPager1.RecordCount % AspNetPager1.PageSize == 0) ? (AspNetPager1.RecordCount / AspNetPager1.PageSize) : ((AspNetPager1.RecordCount / AspNetPager1.PageSize) + 1)).ToString();
lblCurrentPageNum.Text = AspNetPager1.CurrentPageIndex.ToString();
}
private void asppagecount(string sqlstring)
{
using (SqlConnection Conn = new SqlConnection(connectionString))
{
string sqlcount = "Select Count(*) from (" + sqlstring + ") a";
SqlCommand Cmd = new SqlCommand(sqlcount, Conn);
Conn.Open();
this.AspNetPager1.RecordCount = (int)Cmd.ExecuteScalar();
}
}
protected void AspNetPager1_PageChanged(object sender, EventArgs e)
{
GridBind();
}
protected void GridBind()
{
DataSet DS = new DataSet();
StringBuilder sql = new StringBuilder("SELECT dbo.JC_Person_Info.PersonName, dbo.CR_PaiGong.*, dbo.JC_Person_Info.CompCode, dbo.JC_Company_Info.CompName, dbo.JC_Person_Info.DeptCode, dbo.JC_Dept_Info.Deptname FROM dbo.CR_PaiGong INNER JOIN dbo.JC_Person_Info ON dbo.CR_PaiGong.WeiXiuRenYuanID = dbo.JC_Person_Info.ID INNER JOIN dbo.JC_Company_Info ON dbo.JC_Person_Info.CompCode = dbo.JC_Company_Info.CompCode INNER JOIN dbo.JC_Dept_Info ON dbo.JC_Person_Info.DeptCode = dbo.JC_Dept_Info.DeptCode ");
asppagecount(sql.ToString());
SqlDataAdapter Ad = new SqlDataAdapter(sql.ToString(), connectionString);
Ad.Fill(DS, this.AspNetPager1.PageSize * (this.AspNetPager1.CurrentPageIndex - 1), this.AspNetPager1.PageSize, "ds");
if (DS.Tables[0].Rows.Count != 0)
{
GridView1.DataSource = DS;
GridView1.DataBind();
}
else
{
DS.Tables[0].Rows.Add(DS.Tables[0].NewRow());
this.GridView1.DataSource = DS;
this.GridView1.DataBind();
this.GridView1.Rows[0].Visible = false;
}
asppagetitle();
}
4、
手风琴控件,后台无代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Left.aspx.cs" Inherits="BeidouWY.Web.Left" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="Ajax" %>
<!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 id="Head1" runat="server">
<title></title>
<link href="Css/CommStyle.css" rel="Stylesheet" type="text/css" />
<link href="Css/Accordion.css" rel="Stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table width="150" border="0" cellpadding="0" cellspacing="0" style="height: 100%">
<tr>
<td style="width: 4px; background-image: url(images/main_16.gif)">
</td>
<td width="146" valign="top" style="height: 100%">
<table width="100%" border="0" cellspacing="0" cellpadding="0" style="height: 100%">
<tr>
<td height="20" style="background-image: url(images/main_11.gif)">
</td>
</tr>
<tr>
<td valign="top" style="background-image: url('../Images/item_bg.gif')">
<Ajax:Accordion runat="server" ID="accordion" FadeTransitions="false" RequireOpenedPane="true"
AutoSize="None" CssClass="accordion" HeaderCssClass="header" Height="100%">
<Panes>
<Ajax:AccordionPane runat="server" ID="AccordionPane1">
<Header>
<div style="vertical-align: top; height: 28px">
我的办公</div>
</Header>
<Content>
<ul>
<li><a href="OA/MyMessageIndex.aspx" target="Content">我的消息</a></li>
<li><a href="OA/UnitNoticeShow.aspx" target="Content">单位通告</a></li>
<li><a href="OA/MyEmailIndex.aspx" target="Content">我的邮件</a></li>
<li><a href="OA/FM/fmTree.aspx" target="Content">文档管理</a></li>
<li><a href="OA/MyScheduleShow.aspx" target="Content">我的日程</a></li>
</ul>
</Content>
</Ajax:AccordionPane>
<Ajax:AccordionPane runat="server" ID="AccordionPane2">
<Header>
<div style="vertical-align: top; height: 28px">
业主管理</div>
</Header>
<Content>
<ul>
<li><a href="CRManager/HoldManage.aspx" target="Content">新增客户资料</a></li>
<li><a href="CRManager/CRoccupationReg.aspx" target="Content">入伙登记</a> </li>
<li><a href="CRManager/CRoccMoveIn.aspx" target="Content">客户迁入</a></li>
<li><a href="CRManager/CRoccMoveout.aspx" target="Content">客户迁出</a></li>
<li><a href="CRManager/RuZhuXinXi.aspx" target="Content">入住信息</a></li>
</ul>
</Content>
</Ajax:AccordionPane>
<Ajax:AccordionPane runat="server" ID="AccordionPane3">
<Header>
<div style="vertical-align: top; height: 28px">
收费管理</div>
</Header>
<Content>
<ul>
<li><a href="ChargeManage/MeterRead/Index.aspx" target="Content">抄表数据录入</a></li>
<li><a href="ChargeManage/ChargeIndex.aspx" target="Content">费用生成</a> </li>
<li><a href="ChargeManage/Account/Index.aspx" target="Content">收款结帐</a></li>
<li><a href="ChargeManage/ReportIndex.aspx" target="Content">报表打印</a></li>
<li><a href="Messages/MessageShow.aspx?mt=02" target="Content">短信催费</a></li>
</ul>
</Content>
</Ajax:AccordionPane>
<Ajax:AccordionPane runat="server" ID="AccordionPane4">
<Header>
<div style="vertical-align: top; height: 28px">
维修调度</div>
</Header>
<Content>
<ul>
<li><a href="CR_PaiGong/CR_CustomerReportResponse.aspx" target="Content">业主报修</a></li>
<li><a href="CR_PaiGong/CR_PaiGongManager.aspx" target="Content">调度配工</a></li>
<li><a href="CR_PaiGong/index.aspx" target="Content">调度一览表</a></li>
<li><a href="CR_PaiGong/CR_CustomerManYi.aspx" target="Content">客户满意度调查</a></li>
<%--<li><a href="" target="Content">完工反馈</a></li>--%>
</ul>
</Content>
</Ajax:AccordionPane>
<Ajax:AccordionPane runat="server" ID="AccordionPane5">
<Header>
<div style="vertical-align: top; height: 28px">
基础设置</div>
</Header>
<Content>
<ul>
<li><a href="HouseManage/HouseManageIndex.aspx" target="Content">楼房设置</a></li>
<li><a href="ChargeManage/ChargeCS/ChargeCSIndex.aspx" target="Content">收费设置</a></li>
<li><a href="ChargeManage/MeterCS/MeterCSIndex.aspx" target="Content">仪表设置</a></li>
<li><a href="SysManage/MechaSettingIndex.aspx" target="Content">机构设置</a></li>
<li><a href="SysManage/PubDataSetting.aspx" target="Content">公共数据设置</a></li>
</ul>
</Content>
</Ajax:AccordionPane>
<Ajax:AccordionPane runat="server" ID="AccordionPane6">
<Header>
<div style="vertical-align: top; height: 28px">
系统管理</div>
</Header>
<Content>
<ul>
<li><a href="SysManage/UserManage.aspx" target="Content">用户管理</a></li>
<li><a href="SysManage/LogManage.aspx" target="Content">日志管理</a></li>
</ul>
</Content>
</Ajax:AccordionPane>
</Panes>
</Ajax:Accordion>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
5、
利用DataSet创建表关系
string strSql = "Select bxdh,pgdh,khxm,jjcd,lxdh,personname,wgbfb from V_Pg_CustomerReport where (sjwgsj is null or wgbfb<100)";
strSql += " Select id, personid,bxdh,Personname,kssj,wgsj,wgbfb,bz from V_PG_DispacthPerson where (gcsjwgsj is null or gcwgbfb<100)";
ds = DbHelperSQL.Query(strSql);//将查询出来的结果放在DataSet中,里面存放着查询出来的两张表
DataColumn[] parentcolumn = new DataColumn[1]; //创建列数组(表中的一列),长度为1
parentcolumn[0] = ds.Tables[0].Columns["bxdh"];//给这一列附值
DataColumn[] childcolumn = new DataColumn[1];
childcolumn[0] = ds.Tables[1].Columns["bxdh"];
DataRelation rel = new DataRelation(string.Empty, parentcolumn, childcolumn);//创建表关系:DataRelation(关系名称,父列,子列)
ds.Relations.Add(rel);//将创建好的关系添加到DataSet中
6、
ds.Tables[1].DefaultView.RowFilter = "bxdh='" + bxdh + "'"; //将DataSet中的表1中的默认视图进行行过滤,过滤的条件是列bxdh=...
DataTable dt = ds.Tables[1].DefaultView.ToTable();//将过滤出来的默认视图转换成表,并赋值给DataTable
7、
可以设定年月日时分秒的日期控件
<script language="javascript" type="text/javascript" src="../JavaScript/Calendar.js"></script>
<asp:TextBox ID="txtyysj" MaxLength="50" runat="server" onclick="setDayHM(this)"></asp:TextBox>
Calendar.js文件中的内容:
{
-------------------------------------------------------------------------------------------------
/**
*本日历选择控件由tiannet根据前人经验完善而得。大部分代码来自meizz的日历控件。
*tiannet添加了时间选择功能、select,object标签隐藏功能,还有其它小功能。
*使用方法:
* (1)只选择日期 <input type="text" name="date" readOnly onClick="setDay(this);">
* (2)选择日期和小时 <input type="text" name="dateh" readOnly onClick="setDayH(this);">
* (3)选择日期和小时及分钟 <input type="text" name="datehm" readOnly onClick="setDayHM(this);">
*设置参数的方法
* (1)设置日期分隔符 setDateSplit(strSplit);默认为"-"
* (2)设置日期与时间之间的分隔符 setDateTimeSplit(strSplit);默认为" "
* (3)设置时间分隔符 setTimeSplit(strSplit);默认为":"
* (4)设置(1),(2),(3)中的分隔符 setSplit(strDateSplit,strDateTimeSplit,strTimeSplit);
* (5)设置开始和结束年份 setYearPeriod(intDateBeg,intDateEnd)
*说明:
* 默认返回的日期时间格式如同:2005-02-02 08:08
*/
//------------------ 样式定义 ---------------------------//
//功能按钮同样样式
var s_tiannet_turn_base = "height:16px;font-size:9pt;color:white;border:0 solid #CCCCCC;cursor:hand;background-color:#2650A6;";
//翻年、月等的按钮
var s_tiannet_turn = "width:28px;" + s_tiannet_turn_base;
//关闭、清空等按钮样式
var s_tiannet_turn2 = "width:22px;" + s_tiannet_turn_base;
//年选择下拉框
var s_tiannet_select = "width:64px;display:none;";
//月、时、分选择下拉框
var s_tiannet_select2 = "width:46px;display:none;";
//日期选择控件体的样式
var s_tiannet_body = "width:150;background-color:#2650A6;display:none;z-index:9998;position:absolute;" +
"border-left:1 solid #CCCCCC;border-top:1 solid #CCCCCC;border-right:1 solid #999999;border-bottom:1 solid #999999;";
//显示日的td的样式
var s_tiannet_day = "width:21px;height:20px;background-color:#D8F0FC;font-size:10pt;";
//字体样式
var s_tiannet_font = "color:#FFCC00;font-size:9pt;cursor:hand;";
//链接的样式
var s_tiannet_link = "text-decoration:none;font-size:9pt;color:#2650A6;";
//横线
var s_tiannet_line = "border-bottom:1 solid #6699CC";
//------------------ 变量定义 ---------------------------//
var tiannetYearSt = 1950; //可选择的开始年份
var tiannetYearEnd = 2050; //可选择的结束年份
var tiannetDateNow = new Date();
var tiannetYear = tiannetDateNow.getFullYear(); //定义年的变量的初始值
var tiannetMonth = tiannetDateNow.getMonth() + 1; //定义月的变量的初始值
var tiannetDay = tiannetDateNow.getDate();
var tiannetHour = tiannetDateNow.getHours();
var tiannetMinute = tiannetDateNow.getMinutes();
var tiannetArrDay = new Array(42); //定义写日期的数组
var tiannetDateSplit = "-"; //日期的分隔符号
var tiannetDateTimeSplit = " "; //日期与时间之间的分隔符
var tiannetTimeSplit = ":"; //时间的分隔符号
var tiannetOutObject; //接收日期时间的对象
var arrTiannetHide = new Array(); //被强制隐藏的标签
var m_bolShowHour = false; //是否显示小时
var m_bolShowMinute = false; //是否显示分钟
var m_aMonHead = new Array(12); //定义阳历中每个月的最大天数
m_aMonHead[0] = 31; m_aMonHead[1] = 28; m_aMonHead[2] = 31; m_aMonHead[3] = 30; m_aMonHead[4] = 31; m_aMonHead[5] = 30;
m_aMonHead[6] = 31; m_aMonHead[7] = 31; m_aMonHead[8] = 30; m_aMonHead[9] = 31; m_aMonHead[10] = 30; m_aMonHead[11] = 31;
// ---------------------- 用户可调用的函数 -----------------------------//
//用户主调函数-只选择日期
function setDay(obj) {
tiannetOutObject = obj;
//如果标签中有值,则将日期初始化为当前值
var strValue = tiannetTrim(tiannetOutObject.value);
if (strValue != "") {
tiannetInitDate(strValue);
}
tiannetPopCalendar();
}
//用户主调函数-选择日期和小时
function setDayH(obj) {
tiannetOutObject = obj;
m_bolShowHour = true;
//如果标签中有值,则将日期和小时初始化为当前值
var strValue = tiannetTrim(tiannetOutObject.value);
if (strValue != "") {
tiannetInitDate(strValue.substring(0, 10));
var hour = strValue.substring(11, 13);
if (hour < 10) tiannetHour = hour.substring(1, 2);
}
tiannetPopCalendar();
}
//用户主调函数-选择日期和小时及分钟
function setDayHM(obj) {
tiannetOutObject = obj;
m_bolShowHour = true;
m_bolShowMinute = true;
//如果标签中有值,则将日期和小时及分钟初始化为当前值
var strValue = tiannetTrim(tiannetOutObject.value);
if (strValue != "") {
tiannetInitDate(strValue.substring(0, 10));
var time = strValue.substring(11, 16);
var arr = time.split(tiannetTimeSplit);
tiannetHour = arr[0];
tiannetMinute = arr[1];
if (tiannetHour < 10) tiannetHour = tiannetHour.substring(1, 2);
if (tiannetMinute < 10) tiannetMinute = tiannetMinute.substring(1, 2);
}
tiannetPopCalendar();
}
//设置开始日期和结束日期
function setYearPeriod(intDateBeg, intDateEnd) {
tiannetYearSt = intDateBeg;
tiannetYearEnd = intDateEnd;
}
//设置日期分隔符。默认为"-"
function setDateSplit(strDateSplit) {
tiannetDateSplit = strDateSplit;
}
//设置日期与时间之间的分隔符。默认为" "
function setDateTimeSplit(strDateTimeSplit) {
tiannetDateTimeSplit = strDateTimeSplit;
}
//设置时间分隔符。默认为":"
function setTimeSplit(strTimeSplit) {
tiannetTimeSplit = strTimeSplit;
}
//设置分隔符
function setSplit(strDateSplit, strDateTimeSplit, strTimeSplit) {
tiannetDateSplit(strDateSplit);
tiannetDateTimeSplit(strDateTimeSplit);
tiannetTimeSplit(strTimeSplit);
}
//设置默认的日期。格式为:YYYY-MM-DD
function setDefaultDate(strDate) {
tiannetYear = strDate.substring(0, 4);
tiannetMonth = strDate.substring(5, 7);
tiannetDay = strDate.substring(8, 10);
}
//设置默认的时间。格式为:HH24:MI
function setDefaultTime(strTime) {
tiannetHour = strTime.substring(0, 2);
tiannetMinute = strTime.substring(3, 5);
}
// ---------------------- end 用户可调用的函数 -----------------------------//
//------------------ begin 页面显示部分 ---------------------------//
var weekName = new Array("日", "一", "二", "三", "四", "五", "六");
document.write('<div id="divTiannetDate" style="' + s_tiannet_body + '" style="本日历选择控件由tiannet根据前人经验完善而成!">');
document.write('<div align="center" id="divTiannetDateText" Author="tiannet" style="padding-top:2px;">');
document.write('<span id="tiannetYearHead" Author="tiannet" style="' + s_tiannet_font + '" ' +
'onclick="spanYearCEvent();"> 年</span>');
document.write('<select id="selTianYear" style="' + s_tiannet_select + '" Author="tiannet" ' +
' onChange="tiannetYear=this.value;tiannetSetDay(tiannetYear,tiannetMonth);document.all.tiannetYearHead.style.display=\'\';' +
'this.style.display=\'none\';">');
for (var i = tiannetYearSt; i <= tiannetYearEnd; i++) {
document.writeln('<option value="' + i + '">' + i + '年</option>');
}
document.write('</select>');
document.write('<span id="tiannetMonthHead" Author="tiannet" style="' + s_tiannet_font + '" ' +
'onclick="spanMonthCEvent();"> 月</span>');
document.write('<select id="selTianMonth" style="' + s_tiannet_select2 + '" Author="tiannet" ' +
'onChange="tiannetMonth=this.value;tiannetSetDay(tiannetYear,tiannetMonth);document.all.tiannetMonthHead.style.display=\'\';' +
'this.style.display=\'none\';">');
for (var i = 1; i <= 12; i++) {
document.writeln('<option value="' + i + '">' + i + '月</option>');
}
document.write('</select>');
//document.write('</div>');
//document.write('<div align="center" id="divTiannetTimeText" Author="tiannet">');
document.write('<span id="tiannetHourHead" Author="tiannet" style="' + s_tiannet_font + 'display:none;" ' +
'onclick="spanHourCEvent();"> 时</span>');
document.write('<select id="selTianHour" style="' + s_tiannet_select2 + 'display:none;" Author="tiannet" ' +
' onChange="tiannetHour=this.value;tiannetWriteHead();document.all.tiannetHourHead.style.display=\'\';' +
'this.style.display=\'none\';">');
for (var i = 0; i <= 23; i++) {
document.writeln('<option value="' + i + '">' + i + '时</option>');
}
document.write('</select>');
document.write('<span id="tiannetMinuteHead" Author="tiannet" style="' + s_tiannet_font + 'display:none;" ' +
'onclick="spanMinuteCEvent();"> 分</span>');
document.write('<select id="selTianMinute" style="' + s_tiannet_select2 + 'display:none;" Author="tiannet" ' +
' onChange="tiannetMinute=this.value;tiannetWriteHead();document.all.tiannetMinuteHead.style.display=\'\';' +
'this.style.display=\'none\';">');
for (var i = 0; i <= 59; i++) {
document.writeln('<option value="' + i + '">' + i + '分</option>');
}
document.write('</select>');
document.write('</div>');
//输出一条横线
document.write('<div style="' + s_tiannet_line + '"></div>');
document.write('<div align="center" id="divTiannetTurn" style="border:0;" Author="tiannet">');
document.write('<input type="button" style="' + s_tiannet_turn + '" value="年↑" title="上一年" onClick="tiannetPrevYear();">');
document.write('<input type="button" style="' + s_tiannet_turn + '" value="年↓" title="下一年" onClick="tiannetNextYear();"> ');
document.write('<input type="button" style="' + s_tiannet_turn + '" value="月↑" title="上一月" onClick="tiannetPrevMonth();">');
document.write('<input type="button" style="' + s_tiannet_turn + '" value="月↓" title="下一月" onClick="tiannetNextMonth();">');
document.write('</div>');
//输出一条横线
document.write('<div style="' + s_tiannet_line + '"></div>');
document.write('<table border=0 cellspacing=0 cellpadding=0 bgcolor=white onselectstart="return false">');
document.write(' <tr style="background-color:#2650A6;font-size:10pt;color:white;height:22px;" Author="tiannet">');
for (var i = 0; i < weekName.length; i++) {
//输出星期
document.write('<td width="21" align="center" Author="tiannet">' + weekName[i] + '</td>');
}
document.write(' </tr>');
document.write('</table>');
//输出天的选择
document.write('<table border=0 cellspacing=1 cellpadding=0 bgcolor=white onselectstart="return false">');
var n = 0;
for (var i = 0; i < 5; i++) {
document.write(' <tr align=center id="trTiannetDay' + i + '" >');
for (var j = 0; j < 7; j++) {
document.write('<td align="center" id="tdTiannetDay' + n + '" ' +
'onClick="tiannetDay=this.innerText;tiannetSetValue(true);" '
+ ' style="' + s_tiannet_day + '"> </td>');
n++;
}
document.write(' </tr>');
}
document.write(' <tr align=center id="trTiannetDay5" >');
document.write('<td align="center" id="tdTiannetDay35" onClick="tiannetDay=this.innerText;tiannetSetValue(true);" '
+ ' style="' + s_tiannet_day + '"> </td>');
document.write('<td align="center" id="tdTiannetDay36" onClick="tiannetDay=this.innerText;tiannetSetValue(true);" '
+ ' style="' + s_tiannet_day + '"> </td>');
document.write('<td align="right" colspan="5"><a href="javascript:tiannetClear();" style="' + s_tiannet_link + '">清空</a>' +
' <a href="javascript:tiannetHideControl();" style="' + s_tiannet_link + '">关闭</a>' +
' <a href="javascript:tiannetSetValue(true);" style="' + s_tiannet_link + '">确定</a> ' +
'</td>');
document.write(' </tr>');
document.write('</table>');
document.write('</div>');
//------------------ end 页面显示部分 ---------------------------//
//------------------ 显示日期时间的span标签响应事件 ---------------------------//
//单击年份span标签响应
function spanYearCEvent() {
hideElementsById(new Array("selTianYear", "tiannetMonthHead"), false);
if (m_bolShowHour) hideElementsById(new Array("tiannetHourHead"), false);
if (m_bolShowMinute) hideElementsById(new Array("tiannetMinuteHead"), false);
hideElementsById(new Array("tiannetYearHead", "selTianMonth", "selTianHour", "selTianMinute"), true);
}
//单击月份span标签响应
function spanMonthCEvent() {
hideElementsById(new Array("selTianMonth", "tiannetYearHead"), false);
if (m_bolShowHour) hideElementsById(new Array("tiannetHourHead"), false);
if (m_bolShowMinute) hideElementsById(new Array("tiannetMinuteHead"), false);
hideElementsById(new Array("tiannetMonthHead", "selTianYear", "selTianHour", "selTianMinute"), true);
}
//单击小时span标签响应
function spanHourCEvent() {
hideElementsById(new Array("tiannetYearHead", "tiannetMonthHead"), false);
if (m_bolShowHour) hideElementsById(new Array("selTianHour"), false);
if (m_bolShowMinute) hideElementsById(new Array("tiannetMinuteHead"), false);
hideElementsById(new Array("tiannetHourHead", "selTianYear", "selTianMonth", "selTianMinute"), true);
}
//单击分钟span标签响应
function spanMinuteCEvent() {
hideElementsById(new Array("tiannetYearHead", "tiannetMonthHead"), false);
if (m_bolShowHour) hideElementsById(new Array("tiannetHourHead"), false);
if (m_bolShowMinute) hideElementsById(new Array("selTianMinute"), false);
hideElementsById(new Array("tiannetMinuteHead", "selTianYear", "selTianMonth", "selTianHour"), true);
}
//根据标签id隐藏或显示标签
function hideElementsById(arrId, bolHide) {
var strDisplay = "";
if (bolHide) strDisplay = "none";
for (var i = 0; i < arrId.length; i++) {
var obj = document.getElementById(arrId[i]);
obj.style.display = strDisplay;
}
}
//------------------ end 显示日期时间的span标签响应事件 ---------------------------//
//判断某年是否为闰年
function isPinYear(year) {
var bolRet = false;
if (0 == year % 4 && ((year % 100 != 0) || (year % 400 == 0))) {
bolRet = true;
}
return bolRet;
}
//得到一个月的天数,闰年为29天
function getMonthCount(year, month) {
var c = m_aMonHead[month - 1];
if ((month == 2) && isPinYear(year)) c++;
return c;
}
//重新设置当前的日。主要是防止在翻年、翻月时,当前日大于当月的最大日
function setRealDayCount() {
if (tiannetDay > getMonthCount(tiannetYear, tiannetMonth)) {
//如果当前的日大于当月的最大日,则取当月最大日
tiannetDay = getMonthCount(tiannetYear, tiannetMonth);
}
}
//在个位数前加零
function addZero(value) {
if (value < 10) {
value = "0" + value;
}
return value;
}
//取出空格
function tiannetTrim(str) {
return str.replace(/(^\s*)|(\s*$)/g, "");
}
//为select创建一个option
function createOption(objSelect, value, text) {
var option = document.createElement("OPTION");
option.value = value;
option.text = text;
objSelect.options.add(option);
}
//往前翻 Year
function tiannetPrevYear() {
if (tiannetYear > 999 && tiannetYear < 10000) { tiannetYear--; }
else { alert("年份超出范围(1000-9999)!"); }
tiannetSetDay(tiannetYear, tiannetMonth);
//如果年份小于允许的最小年份,则创建对应的option
if (tiannetYear < tiannetYearSt) {
tiannetYearSt = tiannetYear;
createOption(document.all.selTianYear, tiannetYear, tiannetYear + "年");
}
checkSelect(document.all.selTianYear, tiannetYear);
tiannetWriteHead();
}
//往后翻 Year
function tiannetNextYear() {
if (tiannetYear > 999 && tiannetYear < 10000) { tiannetYear++; }
else { alert("年份超出范围(1000-9999)!"); return; }
tiannetSetDay(tiannetYear, tiannetMonth);
//如果年份超过允许的最大年份,则创建对应的option
if (tiannetYear > tiannetYearEnd) {
tiannetYearEnd = tiannetYear;
createOption(document.all.selTianYear, tiannetYear, tiannetYear + "年");
}
checkSelect(document.all.selTianYear, tiannetYear);
tiannetWriteHead();
}
//选择今天
function tiannetToday() {
tiannetYear = tiannetDateNow.getFullYear();
tiannetMonth = tiannetDateNow.getMonth() + 1;
tiannetDay = tiannetDateNow.getDate();
tiannetSetValue(true);
//tiannetSetDay(tiannetYear,tiannetMonth);
//selectObject();
}
//往前翻月份
function tiannetPrevMonth() {
if (tiannetMonth > 1) { tiannetMonth-- } else { tiannetYear--; tiannetMonth = 12; }
tiannetSetDay(tiannetYear, tiannetMonth);
checkSelect(document.all.selTianMonth, tiannetMonth);
tiannetWriteHead();
}
//往后翻月份
function tiannetNextMonth() {
if (tiannetMonth == 12) { tiannetYear++; tiannetMonth = 1 } else { tiannetMonth++ }
tiannetSetDay(tiannetYear, tiannetMonth);
checkSelect(document.all.selTianMonth, tiannetMonth);
tiannetWriteHead();
}
//向span标签中写入年、月、时、分等数据
function tiannetWriteHead() {
document.all.tiannetYearHead.innerText = tiannetYear + "年";
document.all.tiannetMonthHead.innerText = tiannetMonth + "月";
if (m_bolShowHour) document.all.tiannetHourHead.innerText = " " + tiannetHour + "时";
if (m_bolShowMinute) document.all.tiannetMinuteHead.innerText = tiannetMinute + "分";
tiannetSetValue(false); //给文本框赋值,但不隐藏本控件
}
//设置显示天
function tiannetSetDay(yy, mm) {
setRealDayCount(); //设置当月真实的日
tiannetWriteHead();
var strDateFont1 = "", strDateFont2 = "" //处理日期显示的风格
for (var i = 0; i < 37; i++) { tiannetArrDay[i] = "" }; //将显示框的内容全部清空
var day1 = 1;
var firstday = new Date(yy, mm - 1, 1).getDay(); //某月第一天的星期几
for (var i = firstday; day1 < getMonthCount(yy, mm) + 1; i++) {
tiannetArrDay[i] = day1; day1++;
}
//如果用于显示日的最后一行的第一个单元格的值为空,则隐藏整行。
//if(tiannetArrDay[35] == ""){
// document.all.trTiannetDay5.style.display = "none";
//} else {
// document.all.trTiannetDay5.style.display = "";
//}
for (var i = 0; i < 37; i++) {
var da = eval("document.all.tdTiannetDay" + i) //书写新的一个月的日期星期排列
if (tiannetArrDay[i] != "") {
//判断是否为周末,如果是周末,则改为红色字体
if (i % 7 == 0 || (i + 1) % 7 == 0) {
strDateFont1 = "<font color=#f0000>"
strDateFont2 = "</font>"
} else {
strDateFont1 = "";
strDateFont2 = ""
}
da.innerHTML = strDateFont1 + tiannetArrDay[i] + strDateFont2;
//如果是当前选择的天,则改变颜色
if (tiannetArrDay[i] == tiannetDay) {
da.style.backgroundColor = "#CCCCCC";
} else {
da.style.backgroundColor = "#EFEFEF";
}
da.style.cursor = "hand"
} else {
da.innerHTML = ""; da.style.backgroundColor = ""; da.style.cursor = "default"
}
} //end for
tiannetSetValue(false); //给文本框赋值,但不隐藏本控件
} //end function tiannetSetDay
//根据option的值选中option
function checkSelect(objSelect, selectValue) {
var count = parseInt(objSelect.length);
if (selectValue < 10 && selectValue.toString().length == 2) {
selectValue = selectValue.substring(1, 2);
}
for (var i = 0; i < count; i++) {
if (objSelect.options[i].value == selectValue) {
objSelect.selectedIndex = i;
break;
}
} //for
}
//选中年、月、时、分等下拉框
function selectObject() {
//如果年份小于允许的最小年份,则创建对应的option
if (tiannetYear < tiannetYearSt) {
for (var i = tiannetYear; i < tiannetYearSt; i++) {
createOption(document.all.selTianYear, i, i + "年");
}
tiannetYearSt = tiannetYear;
}
//如果年份超过允许的最大年份,则创建对应的option
if (tiannetYear > tiannetYearEnd) {
for (var i = tiannetYearEnd + 1; i <= tiannetYear; i++) {
createOption(document.all.selTianYear, i, i + "年");
}
tiannetYearEnd = tiannetYear;
}
checkSelect(document.all.selTianYear, tiannetYear);
checkSelect(document.all.selTianMonth, tiannetMonth);
if (m_bolShowHour) checkSelect(document.all.selTianHour, tiannetHour);
if (m_bolShowMinute) checkSelect(document.all.selTianMinute, tiannetMinute);
}
//给接受日期时间的控件赋值
//参数bolHideControl - 是否隐藏控件
function tiannetSetValue(bolHideControl) {
var value = "";
if (!tiannetDay || tiannetDay == "") {
tiannetOutObject.value = value;
return;
}
var mm = tiannetMonth;
var day = tiannetDay;
if (mm < 10 && mm.toString().length == 1) mm = "0" + mm;
if (day < 10 && day.toString().length == 1) day = "0" + day;
value = tiannetYear + tiannetDateSplit + mm + tiannetDateSplit + day;
if (m_bolShowHour) {
var hour = tiannetHour;
if (hour < 10 && hour.toString().length == 1) hour = "0" + hour;
value += tiannetDateTimeSplit + hour;
}
if (m_bolShowMinute) {
var minute = tiannetMinute;
if (minute < 10 && minute.toString().length == 1) minute = "0" + minute;
value += tiannetTimeSplit + minute;
}
tiannetOutObject.value = value;
//document.all.divTiannetDate.style.display = "none";
if (bolHideControl) {
tiannetHideControl();
}
}
//是否显示时间
function showTime() {
if (!m_bolShowHour && m_bolShowMinute) {
alert("如果要选择分钟,则必须可以选择小时!");
return;
}
hideElementsById(new Array("tiannetHourHead", "selTianHour", "tiannetMinuteHead", "selTianMinute"), true);
if (m_bolShowHour) {
//显示小时
hideElementsById(new Array("tiannetHourHead"), false);
}
if (m_bolShowMinute) {
//显示分钟
hideElementsById(new Array("tiannetMinuteHead"), false);
}
}
//弹出显示日历选择控件,以让用户选择
function tiannetPopCalendar() {
//隐藏下拉框,显示相对应的head
hideElementsById(new Array("selTianYear", "selTianMonth", "selTianHour", "selTianMinute"), true);
hideElementsById(new Array("tiannetYearHead", "tiannetMonthHead", "tiannetHourHead", "tiannetMinuteHead"), false);
tiannetSetDay(tiannetYear, tiannetMonth);
tiannetWriteHead();
showTime();
var dads = document.all.divTiannetDate.style;
var iX, iY;
var h = document.all.divTiannetDate.offsetHeight;
var w = document.all.divTiannetDate.offsetWidth;
//计算left
if (window.event.x + h > document.body.offsetWidth - 10)
iX = window.event.x - h - 5;
else
iX = window.event.x + 5;
if (iX < 0)
iX = 0;
//计算top
iY = window.event.y;
if (window.event.y + w > document.body.offsetHeight - 10)
iY = document.body.scrollTop + document.body.offsetHeight - w - 5;
else
iY = document.body.scrollTop + window.event.y + 5;
if (iY < 0)
iY = 0;
dads.left = iX;
dads.top = iY;
tiannetShowControl();
selectObject();
}
//隐藏日历控件(同时显示被强制隐藏的标签)
function tiannetHideControl() {
document.all.divTiannetDate.style.display = "none";
tiannetShowObject();
arrTiannetHide = new Array(); //将被隐藏的标签对象清空
}
//显示日历控件(同时隐藏会遮挡的标签)
function tiannetShowControl() {
document.all.divTiannetDate.style.display = "";
tiannetHideObject("SELECT");
tiannetHideObject("OBJECT");
}
//根据标签名称隐藏标签。如会遮住控件的select,object
function tiannetHideObject(strTagName) {
x = document.all.divTiannetDate.offsetLeft;
y = document.all.divTiannetDate.offsetTop;
h = document.all.divTiannetDate.offsetHeight;
w = document.all.divTiannetDate.offsetWidth;
for (var i = 0; i < document.all.tags(strTagName).length; i++) {
var obj = document.all.tags(strTagName)[i];
if (!obj || !obj.offsetParent)
continue;
// 获取元素对于BODY标记的相对坐标
var objLeft = obj.offsetLeft;
var objTop = obj.offsetTop;
var objHeight = obj.offsetHeight;
var objWidth = obj.offsetWidth;
var objParent = obj.offsetParent;
while (objParent.tagName.toUpperCase() != "BODY") {
objLeft += objParent.offsetLeft;
objTop += objParent.offsetTop;
objParent = objParent.offsetParent;
}
//alert("控件左端:" + x + "select左端" + (objLeft + objWidth) + "控件底部:" + (y+h) + "select高:" + objTop);
var bolHide = true;
if (obj.style.display == "none" || obj.style.visibility == "hidden" || obj.getAttribute("Author") == "tiannet") {
//如果标签本身就是隐藏的,则不需要再隐藏。如果是控件中的下拉框,也不用隐藏。
bolHide = false;
}
if (((objLeft + objWidth) > x && (y + h + 20) > objTop && (objTop + objHeight) > y && objLeft < (x + w)) && bolHide) {
//arrTiannetHide.push(obj);//记录被隐藏的标签对象
arrTiannetHide[arrTiannetHide.length] = obj;
obj.style.visibility = "hidden";
}
}
}
//显示被隐藏的标签
function tiannetShowObject() {
for (var i = 0; i < arrTiannetHide.length; i++) {
//alert(arrTiannetHide[i]);
arrTiannetHide[i].style.visibility = "";
}
}
//初始化日期。
function tiannetInitDate(strDate) {
var arr = strDate.split(tiannetDateSplit);
tiannetYear = arr[0];
tiannetMonth = arr[1];
tiannetDay = arr[2];
}
//清空
function tiannetClear() {
tiannetOutObject.value = "";
tiannetHideControl();
}
//任意点击时关闭该控件
function document.onclick() {
with (window.event.srcElement) {
if (tagName != "INPUT" && getAttribute("Author") != "tiannet")
tiannetHideControl();
}
}
//按ESC键关闭该控件
function document.onkeypress() {
if (event.keyCode == 27) {
tiannetHideControl();
}
}
-------------------------------------------------------------------------------------------------
}
8、
物料管理的代码(用的是Repeater和GridView的配合使用,在一个页面实现对一张表的增删改,并且能进行联查显示,Repeater进行主表部分的显示,GridView进行子表部分的显示,在Gridview的主体部分进行子表内容的显示,在页脚部分进行子表内容的添加)
DispatchMaterialManager.aspx前台代码:
{
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="DispatchMaterialManager.aspx.cs"
Inherits="BeidouWY.Web.PGManage.DispatchMaterialManager" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!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 id="Head1" runat="server">
<title>维修物料费用管理</title>
<link href="../Css/CommStyle.css" rel="Stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="../JavaScript/JSBase.js"></script>
<script language="javascript" type="text/javascript" src="../JavaScript/Calendar.js"></script>
<script type="text/javascript" language="javascript">
function expand(obj, classid) {
var objrow = document.getElementById("row_" + classid);
if (obj.innerHTML == "+") {
obj.innerHTML = "-";
objrow.style.display = "";
}
else {
obj.innerHTML = "+";
objrow.style.display = "none";
}
}
function expandall(classid) {
var objrow = document.getElementById("row_" + classid);
objrow.style.display = "";
document.getElementById("Span1").innerHTML = "-";
}
function jisuan(ob) {
if (ob.value != "" && ob.parentNode.parentNode.childNodes[4].childNodes[0].value != "") {
var dj = ob.value;
var shuliang = ob.parentNode.parentNode.childNodes[4].childNodes[0].value;
if (isNaN(dj * shuliang) != true) {
ob.parentNode.parentNode.childNodes[6].childNodes[0].value = dj * shuliang;
}
else {
alert("数量输入错误,请重新输入");
ob.parentNode.parentNode.childNodes[6].childNodes[0].value = "";
ob.value = "";
ob.parentNode.parentNode.childNodes[4].childNodes[0].value = "";
}
}
}
function jisuanshuliang(ob) {
if (ob.value != "" && ob.parentNode.parentNode.childNodes[5].childNodes[0].value != "") {
var dj = ob.value;
var shuliang = ob.parentNode.parentNode.childNodes[5].childNodes[0].value;
if (isNaN(dj * shuliang) != true) {
ob.parentNode.parentNode.childNodes[6].childNodes[0].value = dj * shuliang;
}
else {
alert("数量输入错误,请重新输入");
ob.parentNode.parentNode.childNodes[6].childNodes[0].value = "";
ob.value = "";
ob.parentNode.parentNode.childNodes[5].childNodes[0].value = "";
}
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table width="100%" class="tablemain" border="1" bordercolor="#99CC33">
<tr>
<td class="tdhead">
维修物料费用管理
</td>
</tr>
<tr>
<td>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Repeater runat="server" ID="Repeater1" OnItemDataBound="Repeater1_ItemDataBound">
<HeaderTemplate>
<table id="table" border="1px" cellpadding="3" cellspacing="0" width="100%">
<tr>
<td>
展开/闭合
</td>
<td>
报修单号
</td>
<td>
派工单号
</td>
<td>
客户姓名
</td>
<td>
紧急程度
</td>
<td>
电话
</td>
<td>
负责人
</td>
<td>
完工程度
</td>
</tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<span id="Span1" style="cursor: pointer;" onclick="expand(this,'<%# Eval("bxdh") %>');">
+</span>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "bxdh")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "pgdh")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "khxm")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "jjcd")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "lxdh")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "personname")%>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "wgbfb")%>
</td>
</tr>
<tr style="display: none;" id='row_<%# Eval("bxdh") %>'>
<td>
</td>
<td colspan="7">
<asp:GridView runat="server" ID="GridView1" SkinID="GridView1" Width="100%" AutoGenerateColumns="False"
ShowFooter="True" DataKeyNames="id" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" />
<asp:TemplateField HeaderText="报修单号">
<ItemTemplate>
<asp:Label runat="server" Text='<%#Bind("bxdh") %>' ID="lblbxdh"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="人员">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("PersonName") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:DropDownList runat="server" ID="DDLPerson" DataValueField="rybh" DataTextField="PersonName">
</asp:DropDownList>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="材料名称">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text="<%#Bind('clmc') %>" MaxLength="50" Width="100px"
onblur="CheckLentgh(this)"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="TextBox1" Width="100px" MaxLength="50" ></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="数量">
<ItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text="<%#Bind('sysl') %>" MaxLength="8" Width="80px" onkeyup="jisuanshuliang(this)"
onblur="CheckLentgh(this)"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ErrorMessage="错误"
ControlToValidate="TextBox2" ValidationExpression="^\d+(\.\d+)?$"></asp:RegularExpressionValidator>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="txtsysl" Width="80px" MaxLength="8" onblur="CheckLentgh(this)" onkeyup="jisuanshuliang(this)"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="错误"
ControlToValidate="txtsysl" ValidationExpression="^\d+(\.\d+)?$"></asp:RegularExpressionValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="单价(元)">
<ItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text="<%#Bind('dj') %>" MaxLength="8" onblur="CheckLentgh(this)" Width="80px" onkeyup="jisuan(this)"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator3" runat="server" ErrorMessage="错误"
ControlToValidate="TextBox3" ValidationExpression="^\d+(\.\d+)?$"></asp:RegularExpressionValidator>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="txtdj" MaxLength="8" onblur="CheckLentgh(this)" Width="80px" onkeyup="jisuan(this)" ></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server" ErrorMessage="错误"
ControlToValidate="txtdj" ValidationExpression="^\d+(\.\d+)?$"></asp:RegularExpressionValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="金额(元)">
<ItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text="<%#Bind('je') %>" MaxLength="8" onblur="CheckLentgh(this)" Width="80px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator5" runat="server" ErrorMessage="错误"
ControlToValidate="TextBox4" ValidationExpression="^\d+(\.\d+)?$"></asp:RegularExpressionValidator>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox runat="server" ID="txtje" MaxLength="8" onblur="CheckLentgh(this)" Width="80px"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator6" runat="server" ErrorMessage="错误"
ControlToValidate="txtje" ValidationExpression="^\d+(\.\d+)?$"></asp:RegularExpressionValidator>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="材料编码">
<ItemTemplate>
<asp:TextBox ID="txtclbm" runat="server" Text='<%#Bind("clbm") %>' MaxLength="10" onblur="CheckLentgh(this)" Width="80px"></asp:TextBox>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtfootclbm" runat="server" MaxLength="10" onblur="CheckLentgh(this)" Width="80px"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:CheckBoxField DataField="shbz" ReadOnly="true" HeaderText="审核" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="true" CommandName="save"
Text="保存"></asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="Button1" runat="server" CommandName="Add" Text="添加" CommandArgument="id" CausesValidation="true" />
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton3" runat="server" CausesValidation="false" CommandArgument='<%#Eval("ID") %>' OnClientClick="Javascript:return confirm('是否删除?');"
CommandName="del" Text="删除"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Repeater1" />
</Triggers>
</asp:UpdatePanel>
</td>
</tr>
<tr>
<td>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
}
DispatchMaterialManager.aspx后台代码:
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BeidouWY.DBUtility;
using System.Text;
using BeidouWY.Common;
namespace BeidouWY.Web.PGManage
{
public partial class DispatchMaterialManager : PageBase
{
private DataSet ds;
protected DataTable PersonDt;
private long caozuorenyuanid = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserInfo"] != null)
{
string[] strUserInfo = Session["UserInfo"].ToString().Split('|');
caozuorenyuanid = Convert.ToInt64(strUserInfo[0]);
}
if (!IsPostBack)
{
this.GridBind();
}
}
private void GridBind()
{
StringBuilder strSql = new StringBuilder();
strSql.Append("Select bxdh,pgdh,khxm,jjcd,lxdh,personname,wgbfb from V_Pg_CustomerReport where (sjwgsj is null or wgbfb<100) ");
strSql.Append("SELECT dbo.PG_DispatchMaterial.*, dbo.JC_Person_Info.PersonName FROM dbo.PG_DispatchMaterial INNER JOIN dbo.JC_Person_Info ON dbo.PG_DispatchMaterial.wxryID = dbo.JC_Person_Info.ID");
ds = DbHelperSQL.Query(strSql.ToString());
this.Repeater1.DataSource = ds.Tables[0];
this.Repeater1.DataBind();
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
string bxdh = ((DataRowView)(e.Item.DataItem)).Row.ItemArray[0].ToString();
GridView gv = (GridView)e.Item.FindControl("GridView1");
this.ChildGridBind(bxdh, gv);
}
}
protected void ChildGridBind(string bxdh, GridView gv)
{
if (ds == null)
{
StringBuilder strSql = new StringBuilder();
strSql.Append("Select bxdh,pgdh,khxm,jjcd,lxdh,personname,wgbfb from V_Pg_CustomerReport where (sjwgsj is null or wgbfb<100) ");
strSql.Append("SELECT dbo.PG_DispatchMaterial.*, dbo.JC_Person_Info.PersonName FROM dbo.PG_DispatchMaterial INNER JOIN dbo.JC_Person_Info ON dbo.PG_DispatchMaterial.wxryID = dbo.JC_Person_Info.ID");
ds = DbHelperSQL.Query(strSql.ToString());
}
ds.Tables[1].DefaultView.RowFilter = "bxdh='" + bxdh + "'";
DataTable dt = ds.Tables[1].DefaultView.ToTable();
//GridView gv = (GridView)e.Item.FindControl("GridView1");
this.GetPerson(bxdh);
if (gv != null && dt.Rows.Count > 0)
{
gv.DataSource = dt;
gv.DataBind();
}
else
{
if (gv != null)
{
dt.Rows.Add(dt.NewRow());
gv.DataSource = dt;
gv.DataBind();
gv.Rows[0].Visible = false;
}
}
gv.FooterRow.Cells[1].Text = bxdh;
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
GridView gv = (GridView)sender;
string strbxdbh = ((System.Web.UI.WebControls.TableRow)(((System.Web.UI.WebControls.GridView)(sender)).FooterRow)).Cells[1].Text;
switch (e.CommandName.ToLower())
{
case "add":
long longwxryid = 0;
float longsysl = 0;
decimal decdj = 0;
decimal decje = 0;
if (Common.PageValidate.StrToLong(((DropDownList)(((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[2].FindControl("DDLPerson"))).SelectedValue) != null)
{
longwxryid = Convert.ToInt64(((DropDownList)(((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[2].FindControl("DDLPerson"))).SelectedValue);
}
else
{
MessageBox.Show(this, "请选择维修人员");
return;
}
string strclmc = ((TextBox)((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[3].FindControl("TextBox1")).Text;
if (PageValidate.StrToDec(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[4].FindControl("txtsysl")).Text) != null)
{
longsysl = Convert.ToSingle(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[4].FindControl("txtsysl")).Text);
}
else
{
MessageBox.Show(this, "使用数量输入不正确");
return;
}
if (PageValidate.StrToDec(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[5].FindControl("txtdj")).Text) != null)
{
decdj = Convert.ToDecimal(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[5].FindControl("txtdj")).Text);
}
else
{
MessageBox.Show(this, "单价输入不正确");
return;
}
if (PageValidate.StrToDec(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[6].FindControl("txtje")).Text) != null)
{
decje = Convert.ToDecimal(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[6].FindControl("txtje")).Text);
}
else
{
MessageBox.Show(this, "金额输入不正确");
return;
}
string strclbm = ((TextBox)((System.Web.UI.WebControls.GridView)(sender)).FooterRow.Cells[7].FindControl("txtfootclbm")).Text;
string sqladd = "insert into PG_DispatchMaterial values('" + strbxdbh + "','" + strclmc + "'," + longsysl + "," + decdj + "," + decje + "," + longwxryid + ",'" + strclbm + "','0',null,null)";
if (caozuorenyuanid != 0)
{
DbHelperSQL.ExecuteSql(sqladd);
}
break;
case "save":
List<string> updatesqls = new List<string>();
if (gv.Rows[0].RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < ((System.Web.UI.WebControls.GridView)(sender)).Rows.Count; i++)
{
long materid = Convert.ToInt64(((System.Web.UI.WebControls.GridView)(sender)).Rows[i].Cells[0].Text);
string materclmc = ((TextBox)((System.Web.UI.WebControls.GridView)(sender)).Rows[i].FindControl("TextBox1")).Text;
float matersysl = 0;
if (PageValidate.StrToDec(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).Rows[i].FindControl("TextBox2")).Text) != null)
{
matersysl = Convert.ToSingle(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).Rows[i].FindControl("TextBox2")).Text);
}
else
{
MessageBox.Show(this, "使用数量输入不正确");
return;
}
decimal materdj = 0;
if (PageValidate.StrToDec(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).Rows[i].FindControl("TextBox3")).Text) != null)
{
materdj = Convert.ToDecimal(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).Rows[i].FindControl("TextBox3")).Text);
}
else
{
MessageBox.Show(this, "单价输入不正确");
return;
}
decimal materje = 0;
if (PageValidate.StrToDec(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).Rows[i].FindControl("TextBox4")).Text) != null)
{
materje = Convert.ToDecimal(((TextBox)((System.Web.UI.WebControls.GridView)(sender)).Rows[i].FindControl("TextBox4")).Text);
}
else
{
MessageBox.Show(this, "金额输入不正确");
return;
}
string materclbm = ((TextBox)((System.Web.UI.WebControls.GridView)(sender)).Rows[i].FindControl("txtclbm")).Text;
if (caozuorenyuanid != 0)
{
updatesqls.Add("update PG_dispatchMaterial set clmc='" + materclmc + "',sysl=" + matersysl + ",dj=" + materdj + ",je=" + materje + ",clbm='" + materclbm + "' where ID='" + materid + "'");
}
}
DbHelperSQL.ExecuteSqlTran(updatesqls);
}
break;
case "del":
long deteid = 0;
try
{
deteid = Convert.ToInt64(e.CommandArgument);
}
catch { }
if (deteid != 0)
{
DbHelperSQL.ExecuteSql("delete from PG_dispatchMaterial where ID='" + deteid + "'");
}
break;
}
this.ChildGridBind(strbxdbh, gv);
Page.ClientScript.RegisterStartupScript(typeof(string), "", "<Script>expandall( '" + strbxdbh + "')</script>");
}
catch (Exception error)
{
MessageBox.Show(this, "您的操作失败"+error.Message+"");
}
}
protected void GridView1_RowCommand(object sender, GridViewRowEventArgs e)
{
//string ss = "aaa";
}
protected void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[0].Attributes.Add("style", "display:none");
e.Row.Cells[1].Attributes.Add("style", "display:none");
//e.Row.Cells[2].Attributes.Add("style", "display:none");
//if (e.Row.RowType == DataControlRowType.DataRow)
//{
// try
// {
// TextBox tb = (TextBox)e.Row.FindControl("TextBox3");
// if (decimal.Parse(tb.Text) == 100)
// {
// e.Row.Cells[10].Visible = false;
// e.Row.Cells[8].Visible = false;
// e.Row.Cells[9].Visible = false;
// }
// }
// catch { }
//}
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList dp = (DropDownList)e.Row.FindControl("DDLPerson");
if (dp != null)
{
dp.DataSource = PersonDt;
dp.DataBind();
}
}
}
protected void GetPerson(string BaoXiuDanBianHao)
{
string strSql = "SELECT dbo.JC_Person_Info.PersonName, dbo.PG_DispatchPerson.* FROM dbo.PG_DispatchPerson INNER JOIN dbo.JC_Person_Info ON dbo.PG_DispatchPerson.rybh = dbo.JC_Person_Info.ID WHERE PG_DispatchPerson.bxdh='" + BaoXiuDanBianHao + "'";
PersonDt = DbHelperSQL.Query(strSql).Tables[0];
}
}
}
}