阅读:4917
回复:6
|
[产品需求]解决查询列表中存在子表显示问题Demo
我们大家都知道,我们现在H3产品可以快速开发出查询画面,当我们遇到查询画面中,存在子表的情况下,该如何显示呢?
下面就现有项目的需求,解决了存在子表多条数据的情况下,解决的一个demo。 先看[img]file:///C:\Users\Koy\AppData\Roaming\Tencent\Users\95178651\QQ\WinTemp\RichOle\5A(}QQDYV{@QR{(NHSPK3HJ.png[/img]一下整体的效果图,是否为大家所需要的。 描述:效果图 图片:QQ图片20160713133003.png 看一下具体代码里边的文件: ------------------------------------------------------------------ BizQueryView.aspx <%@ Page Language="C#" AutoEventWireup="true" CodeFile="BizQueryView.aspx.cs" Inherits="OThinker.H3.Portal.BizQueryView" MasterPageFile="~/DefaultMaster.master" %> <asp:content id="Content1" runat="Server" contentplaceholderid="cphHead"> <title></title><link href="<%=this.PortalResRoot %>/_Content/themes/ligerUI/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" /> <link href="<%=this.PortalResRoot %>/_Content/themes/H3Default/H3-All.css" rel="stylesheet" type="text/css" /> <link href="<%=this.PortalResRoot %>/_Content/themes/H3Default/BizQueryView.css" rel="stylesheet" type="text/css" /> <script src="<%=this.PortalResRoot %>/_Scripts/jquery/jquery.js"></script> <script src="<%=this.PortalResRoot %>/_Scripts/ligerUI/ligerui.all.js" type="text/javascript"></script> <script src="<%=this.PortalResRoot %>/_Scripts/ligerUI/plugins/ligerDrag.js" type="text/javascript"></script> <script src="<%=this.PortalResRoot %>/_Scripts/H3AdminPlugins.js" type="text/javascript"></script> <script src="<%=this.PortalResRoot %>/_Scripts/bizquery.js" type="text/javascript"></script> <link href="<%=this.PortalResRoot %>/_Content/themes/H3Default/CSS_BizQueryView.css" rel="stylesheet" type="text/css" /> <script src="<%=this.PortalResRoot %>/_Scripts/css_popup_layer.js" type="text/javascript"></script> <script type="text/javascript"> // 获取Url var url = window.location.search; // 截取Url最后一位的Function代码 var loc = url.substring(url.lastIndexOf('=') + 1, url.length); // 自定义列 var CustomColumns = []; if ((loc == "Customer_GeneralInfo") || (loc == "Stock_InStorage") || (loc == "Stock_Allocation") || (loc == "Stock_OutStorage") || (loc == "Daily_WorkReport") || (loc == "Daily_BrakeChangeRecord") || (loc == "Stock_ToolManage")) { // 若要添加自定义的列,请参考以下示例 CustomColumns.push({ display: " 更多",//列标题 width: "90px",//宽度 //显示逻辑 render: function (rowData, rowIndex) { return "<div id="" + rowData.ObjectID + "" class="tigger"><a href='javascript:void(0);' class='detailBtn' onclick=DivPopup(\"" + rowData.ObjectID + "\",\""+loc+"\")>详细信息</a></div>" } }); } // 显示DIV信息 function DivPopup(vObjectID,loc) { // 清空Div下的所有内容 $("#divBlk").empty(); // 获取弹出框的Grid数据 $.ajax({ type: "post", async: false, cache: false, url: "Ajax/CSSCommonHandler.ashx?method=QuerySubTableInfo", dataType: "json", data: { "ObjectID": vObjectID,"loc":loc }, success: function (data) { if (data != null && data != "") { var result = eval(data); $("#divBlk").append(result); } else { alert("当前查询子表信息不存在!"); } } }); // 执行弹出框代码 var t4 = new PopupLayer({ trigger: "#" + vObjectID, popupBlk: "#divBlk", closeBtn: "#closeBtn", useFx: true }); t4.doEffects = function (way) { way == "open" ? this.popupLayer.slideDown("slow") : this.popupLayer.slideUp("slow"); }; }; </script> <style type="text/css"> .l-toolbar-item { line-height: 22px; height: auto; } </style> </asp:content> <asp:content id="Content2" runat="Server" contentplaceholderid="cphMain"> <div class="panel"><div id="custem-toolbar" class="panel-heading"><div class="form-inline" role="form"><asp:linkbutton id="btnSearch" runat="server" onclick="btnSearch_Click" cssclass="btn btn-default"><i class="panel-title-icon fa fa-search"></i><%=this.PortalResource.GetString("RunBizQuery_Query")%></asp:linkbutton> <div class="btn-group btn-default" id="query-btn-group"></div></div></div><div class="panel-body" style="min-height:300px;"><div class="row"><asp:panel id="panelSearch" runat="server"> <div class="H3Panel"><asp:table id="tableSearch" runat="server"> </asp:table> </div></asp:panel> </div><div class="row"><div id="masterDataGrid"></div></div></div></div><div id="divBlk" class="blk" style="display:none;"></div></asp:content> ----------------------------------------------------------------------------------------------- --CSS_BizQueryView.css 文件 a.closeBtn { position: absolute; top: 8px; right: 13px; display: block; width: 50px; height: 20px; padding: 1px 0; text-align: center; background: #fff; border: 1px solid gray; color: black; } a.closeBtn:hover { color: black; border: 1px solid gray; background: gray; } a.detailBtn { color: black; text-align: center; } .example { border: 1px dashed #ccc; padding: 40px; margin-top: 10px; zoom: 999999; } .example .tigger { display: block; width: 100%; padding: 10px; text-align: center; background: #fff; border: 1px solid #999; color: #333; cursor: pointer; float: left; } .blk { width: 850px; position: relative; } .blk .main { border: 2px solid gray; position: relative; background: #fff; padding: 25px 5px 5px 13px; width: 100%; } .blk .main h2 { font: bold 23px "Microsoft YaHei"; padding: 8px; color: gray; height: 60px; text-align: center; } .blk .divOverFlow { position: relative; width: 99%; overflow-x: auto; } table.GridTable { font-family: Simsun,宋体,verdana,arial,helvetica,sans-serif; font-size: 13px; color: #333333; border-width: 1px; border-color: #666666; border-collapse: collapse; } table.GridTable th { border-width: 1px; padding: 5px; border-style: solid; border-color: #666666; background-color: #dedede; height: 23px; text-align: center; } table.GridTable td { border-width: 1px; padding: 3px; border-style: solid; border-color: #666666; background-color: #ffffff; } ------------------------------------------------------------------------- css_popup_layer.js Function.prototype.binding = function() { if (arguments.length < 2 && typeof arguments[0] == "undefined") return this; var __method = this, args = jQuery.makeArray(arguments), object = args.shift(); return function() { return __method.apply(object, args.concat(jQuery.makeArray(arguments))); } } var Class = function(subclass){ subclass.setOptions = function(options){ this.options = jQuery.extend({}, this.options,options); for(var key in options){ if(/^on[A-Z][A-Za-z]*$/.test(key)){ $(this).bind(key,options[key]); } } } var fn = function(){ if(subclass._init && typeof subclass._init == 'function'){ this._init.apply(this,arguments); } } if(typeof subclass == 'object'){ fn.prototype = subclass; } return fn; } var PopupLayer = new Class({ options:{ trigger:null, //触发的元素或id,必填参数 popupBlk:null, //弹出内容层元素或id,必填参数 closeBtn: null, //关闭弹出层的元素或id popupLayerClass:"popupLayer", //弹出层容器的class名称 eventType:"click", //触发事件的类型 offsets:{ //弹出层容器位置的调整值 x:-850, y:0 }, useFx:false, //是否使用特效 useOverlay:false, //是否使用全局遮罩 usePopupIframe:true, //是否使用容器遮罩 isresize:true, //是否绑定window对象的resize事件 onBeforeStart:function(){} //自定义事件 }, _init:function(options){ this.setOptions(options); //载入设置 this.isSetPosition = this.isDoPopup = this.isOverlay = true; //定义一些开关 this.popupLayer = $(document.createElement("div")).addClass(this.options.popupLayerClass); //初始化最外层容器 this.popupIframe = $(document.createElement("iframe")).attr({border:0,frameborder:0}); //容器遮罩,用于屏蔽ie6下的select this.trigger = $(this.options.trigger); //把触发元素封装成实例的一个属性,方便使用及理解 this.popupBlk = $(this.options.popupBlk); //把弹出内容层元素封装成实例的一个属性 this.closeBtn = $(this.options.closeBtn); //把关闭按钮素封装成实例的一个属性 $(this).trigger("onBeforeStart"); //执行自定义事件。 this._construct() //通过弹出内容层,构造弹出层,即为其添加外层容器及底层iframe this.trigger.bind(this.options.eventType,function(){ //给触发元素绑定触发事件 if(this.isSetPosition){ this.setPosition(this.trigger.offset().left + this.options.offsets.x, this.trigger.offset().top + this.trigger.get(0).offsetHeight + this.options.offsets.y); } this.options.useOverlay?this._loadOverlay():null; //如果使用遮罩则加载遮罩元素 (this.isOverlay && this.options.useOverlay)?this.overlay.show():null; if(this.isDoPopup && (this.popupLayer.css("display")== "none")){ this.options.useFx?this.doEffects("open"):this.popupLayer.show(); } }.binding(this)); this.isresize?$(window).bind("resize",this.doresize.binding(this)):null; this.options.closeBtn?this.closeBtn.bind("click",this.close.binding(this)):null; //如果有关闭按钮,则给关闭按钮绑定关闭事件 }, _construct:function(){ //构造弹出层 this.popupBlk.show(); this.popupLayer.append(this.popupBlk.css({ opacity: 1 })).appendTo($(document.body)).css({ position: "absolute", 'z-index': 2, width: this.popupBlk.get(0).offsetWidth, height: this.popupBlk.get(0).offsetHeight }); this.options.usePopupIframe?this.popupLayer.append(this.popupIframe):null; this.recalculatePopupIframe(); this.popupLayer.hide(); }, _loadOverlay:function(){ //加载遮罩 pageWidth = ($.browser.version=="6.0")?$(document).width()-21:$(document).width(); this.overlay?this.overlay.remove():null; this.overlay = $(document.createElement("div")); this.overlay.css({position:"absolute","z-index":1,left:0,top:0,zoom:1,display:"none",width:pageWidth,height:$(document).height()}).appendTo($(document.body)).append("<div style='position:absolute;z-index:2;width:100%;height:100%;left:0;top:0;opacity:0.3;filter:Alpha(opacity=30);background:#000'></div><iframe frameborder='0' border='0' style='width:100%;height:100%;position:absolute;z-index:1;left:0;top:0;filter:Alpha(opacity=0);'></iframe>") }, doresize:function(){ this.overlay?this.overlay.css({width:($.browser.version=="6.0")?$(document).width()-21:$(document).width(),height:($.browser.version=="6.0")?$(document).height()-4:$(document).height()}):null; if(this.isSetPosition){ this.setPosition(this.trigger.offset().left + this.options.offsets.x, this.trigger.offset().top + this.trigger.get(0).offsetHeight + this.options.offsets.y); } }, setPosition:function(left,top){ //通过传入的参数值改变弹出层的位置 this.popupLayer.css({left:left,top:top}); }, doEffects:function(way){ //做特效 way == "open"?this.popupLayer.show("slow"):this.popupLayer.hide("slow"); }, recalculatePopupIframe:function(){ //重绘popupIframe,这个不知怎么改进,只好先用这个笨办法。 this.popupIframe.css({position:"absolute",'z-index':-1,left:0,top:0,opacity:0,width:this.popupBlk.get(0).offsetWidth,height:this.popupBlk.get(0).offsetHeight}); }, close: function () { //关闭方法 this.options.useOverlay?this.overlay.hide():null; this.options.useFx?this.doEffects("close"):this.popupLayer.hide(); } }); ---------------------------------------------------------------------- CSSCommon.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Text; namespace OThinker.H3.Portal { /// <summary> /// CSSCommon 的摘要说明 /// </summary> public class CSSCommon { public CSSCommon() { // // TODO: 在此处添加构造函数逻辑 // } /// <summary> /// 产品信息数据转换为Html代码 /// </summary> /// <param name="dt">产品信息</param> /// <returns></returns> public static string SpellSubProductInfo(DataTable dt) { string strResult = string.Empty; int iNo = 1; StringBuilder sbHtml = new StringBuilder(); // 定义Grid表头、Grid标题名称作为参数 sbHtml = DataGridTitle("客户产品子表信息", new string[] { "No.", "服务管理分类名称", "车型/主机名称", "型号/规格名称", "产品名称" }); // 绑定Grid数据 foreach (DataRow row in dt.Rows) { sbHtml.AppendLine("<tr>"); sbHtml.AppendFormat("<td>{0}</td>", iNo.ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_ProductManageType_CName"].ToString()), row["M_ProductManageType_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_CarModel_CName"].ToString()), row["M_CarModel_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_ModelType_CName"].ToString()), row["M_ModelType_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_Product_CName"].ToString()), row["M_Product_CName"].ToString()); sbHtml.AppendLine("</tr>"); iNo++; } sbHtml.AppendLine("</table></div></div>"); return sbHtml.ToString(); } /// <summary> /// 入库信息数据转换为Html代码 /// </summary> /// <param name="dt"></param> /// <returns></returns> public static string SpellSubInStorageInfo(DataTable dt) { string strResult = string.Empty; int iNo = 1; StringBuilder sbHtml = new StringBuilder(); // 定义Grid表头、Grid标题名称作为参数 sbHtml = DataGridTitle("入库信息", new string[] { "No.", "物料代码", "物料规格型号", "物料名称", "物料计量单位","数量","仓库" }); // 绑定Grid数据 foreach (DataRow row in dt.Rows) { sbHtml.AppendLine("<tr>"); sbHtml.AppendFormat("<td>{0}</td>", iNo.ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_Code"].ToString()), row["M_MaterialManage_Code"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_Model"].ToString()), row["M_MaterialManage_Model"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_CName"].ToString()), row["M_MaterialManage_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_Unit"].ToString()), row["M_MaterialManage_Unit"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Quantity"].ToString()), row["Quantity"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_StoreManage_CName"].ToString()), row["M_StoreManage_CName"].ToString()); sbHtml.AppendLine("</tr>"); iNo++; } sbHtml.AppendLine("</table></div></div>"); return sbHtml.ToString(); } /// <summary> /// 出库信息数据转换为Html代码 /// </summary> /// <param name="dt"></param> /// <returns></returns> public static string SpellSubOutStorageInfo(DataTable dt) { string strResult = string.Empty; int iNo = 1; StringBuilder sbHtml = new StringBuilder(); // 定义Grid表头、Grid标题名称作为参数 sbHtml = DataGridTitle("出库信息", new string[] { "No.", "物料代码", "物料名称", "物料规格型号", "物料计量单位", "数量","配件编号", "仓库" }); // 绑定Grid数据 foreach (DataRow row in dt.Rows) { sbHtml.AppendLine("<tr>"); sbHtml.AppendFormat("<td>{0}</td>", iNo.ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_Code"].ToString()), row["M_MaterialManage_Code"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_Model"].ToString()), row["M_MaterialManage_Model"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_CName"].ToString()), row["M_MaterialManage_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_Unit"].ToString()), row["M_MaterialManage_Unit"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Quantity"].ToString()), row["Quantity"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["FittingCode"].ToString()), row["FittingCode"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_StoreManage_CName"].ToString()), row["M_StoreManage_CName"].ToString()); sbHtml.AppendLine("</tr>"); iNo++; } sbHtml.AppendLine("</table></div></div>"); return sbHtml.ToString(); } /// <summary> /// 调拨信息数据转换为Html代码 /// </summary> /// <param name="dt"></param> /// <returns></returns> public static string SpellSubAllocationInfo(DataTable dt) { string strResult = string.Empty; int iNo = 1; StringBuilder sbHtml = new StringBuilder(); // 定义Grid表头、Grid标题名称作为参数 sbHtml = DataGridTitle("调拨信息", new string[] { "No.", "物料代码", "物料名称", "物料规格型号", "物料计量单位", "数量", "调入仓库名称", "调出仓库名称" }); // 绑定Grid数据 foreach (DataRow row in dt.Rows) { sbHtml.AppendLine("<tr>"); sbHtml.AppendFormat("<td>{0}</td>", iNo.ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_Code"].ToString()), row["M_MaterialManage_Code"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_CName"].ToString()), row["M_MaterialManage_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_Model"].ToString()), row["M_MaterialManage_Model"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_MaterialManage_Unit"].ToString()), row["M_MaterialManage_Unit"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Quantity"].ToString()), row["Quantity"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["In_M_StoreManage_CName"].ToString()), row["In_M_StoreManage_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Out_M_StoreManage_CName"].ToString()), row["Out_M_StoreManage_CName"].ToString()); sbHtml.AppendLine("</tr>"); iNo++; } sbHtml.AppendLine("</table></div></div>"); return sbHtml.ToString(); } /// <summary> /// 工具管理信息转换为Html /// </summary> /// <param name="dt"></param> /// <returns></returns> public static string SpellSubToolManageInfo(DataTable dt) { string strResult = string.Empty; int iNo = 1; StringBuilder sbHtml = new StringBuilder(); // 定义Grid表头、Grid标题名称作为参数 sbHtml = DataGridTitle("工具管理信息", new string[] { "No.", "日期", "管理者", "使用状态", "备注" }); // 绑定Grid数据 foreach (DataRow row in dt.Rows) { //日期转换 string strCDate = row["CDate"] != null ? DateTime.Parse(row["CDate"].ToString()).ToString("yyyy-MM-dd") : string.Empty; sbHtml.AppendLine("<tr>"); sbHtml.AppendFormat("<td>{0}</td>", iNo.ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(strCDate), strCDate); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Manager"].ToString()), row["Manager"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["UseState"].ToString()), row["UseState"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Remark"].ToString()), row["Remark"].ToString()); sbHtml.AppendLine("</tr>"); iNo++; } sbHtml.AppendLine("</table></div></div>"); return sbHtml.ToString(); } /// <summary> /// 工作表日志信息数据转换为Html代码 /// </summary> /// <param name="dt"></param> /// <returns></returns> public static string SpellSubWorkReportInfo(DataTable dt) { string strResult = string.Empty; int iNo = 1; StringBuilder sbHtml = new StringBuilder(); // 定义Grid表头、Grid标题名称作为参数 sbHtml = DataGridTitle("日志信息", new string[] { "No.", "服务信息表编号", "客户名称", "现场名称", "所在位置", "工作内容", "加班时间", "完成百分比" }); // 绑定Grid数据 foreach (DataRow row in dt.Rows) { sbHtml.AppendLine("<tr>"); sbHtml.AppendFormat("<td>{0}</td>", iNo.ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["P_ServiceInfo_RecordCode"].ToString()), row["P_ServiceInfo_RecordCode"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["C_GeneralInfo_CName"].ToString()), row["C_GeneralInfo_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["C_SceneInfo_CName"].ToString()), row["C_SceneInfo_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["CurrentPosition"].ToString()), row["CurrentPosition"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Content"].ToString()), row["Content"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["OverTime"].ToString()), row["OverTime"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Percent"].ToString()), row["Percent"].ToString()); sbHtml.AppendLine("</tr>"); iNo++; } sbHtml.AppendLine("</table></div></div>"); return sbHtml.ToString(); } /// <summary> /// 制动盘更换信息数据转换为Html代码 /// </summary> /// <param name="dt"></param> /// <returns></returns> public static string SpellSubBrakeChangeRecordInfo(DataTable dt) { string strResult = string.Empty; int iNo = 1; StringBuilder sbHtml = new StringBuilder(); // 定义Grid表头、Grid标题名称作为参数 sbHtml = DataGridTitle("制动盘更换信息", new string[] { "No.", "日期", "旧制动盘炉号", "旧制动盘炉号", "旧防松垫片生产年", "旧防松垫片生产月", "首次压缩时间", "更换原因", "车型/主机名称", "运行区间", "轴号", "新制动盘炉号", "新制动盘炉号", "新松垫片生产年", "新松垫片生产月", "是否过期", "备注" }); // 绑定Grid数据 foreach (DataRow row in dt.Rows) { // 日期转换 string strCDate = row["CDate"] != null ? DateTime.Parse(row["CDate"].ToString()).ToString("yyyy-MM-dd") : string.Empty; string strFirstInstallDate = row["FirstInstallDate"] != null ? DateTime.Parse(row["FirstInstallDate"].ToString()).ToString("yyyy-MM-dd") : string.Empty; sbHtml.AppendLine("<tr>"); sbHtml.AppendFormat("<td>{0}</td>", iNo.ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(strCDate), strCDate); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["OldBrakeTypeA"].ToString()), row["OldBrakeTypeA"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["OldBrakeTypeB"].ToString()), row["OldBrakeTypeB"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["OldShimProductionYear"].ToString()), row["OldShimProductionYear"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["OldShimProductionMonth"].ToString()), row["OldShimProductionMonth"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(strFirstInstallDate), strFirstInstallDate); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["ChangeCause"].ToString()), row["ChangeCause"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_CarModel_CName"].ToString()), row["M_CarModel_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["OperatingRange"].ToString()), row["OperatingRange"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["BearingModel"].ToString()), row["BearingModel"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["NewBrakeTypeA"].ToString()), row["NewBrakeTypeA"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["NewBrakeTypeB"].ToString()), row["NewBrakeTypeB"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["NewShimProductionYear"].ToString()), row["NewShimProductionYear"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["NewShimProductionMonth"].ToString()), row["NewShimProductionMonth"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["IsOverdue"].ToString()), row["IsOverdue"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Remark"].ToString()), row["Remark"].ToString()); sbHtml.AppendLine("</tr>"); iNo++; } sbHtml.AppendLine("</table></div></div>"); return sbHtml.ToString(); } /// <summary> /// 历史变更记录更换信息数据转换为Html代码 /// </summary> /// <param name="dt"></param> /// <returns></returns> public static string SpellHistoryRecordCodeInfo(DataTable dt) { string strResult = string.Empty; int iNo = 1; StringBuilder sbHtml = new StringBuilder(); // 定义Grid表头、Grid标题名称作为参数 sbHtml = DataGridTitle("历史变更记录信息", new string[] { "No.", "记录日期 ", "客户", "现场", "联系人", "电话", "事件分类", "反馈来源", "服务管理分类", "车型/主机", "产品", "型号/规格", "数量", "修程", "公里数", "响应级别", "发生频次", "反馈性质", "发生原因", "故障部位","故障形式","处理结果","完成百分比" }); // 绑定Grid数据 foreach (DataRow row in dt.Rows) { sbHtml.AppendLine("<tr>"); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", iNo.ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["RecordDate"].ToString()), row["RecordDate"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["C_GeneralInfo_CName"].ToString()), row["C_GeneralInfo_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["C_SceneInfo_CName"].ToString()), row["C_SceneInfo_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["C_Contacts_Contacts"].ToString()), row["C_Contacts_Contacts"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["C_Contacts_Mobile"].ToString()), row["C_Contacts_Mobile"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["EventType"].ToString()), row["EventType"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["FeedBackSource"].ToString()), row["FeedBackSource"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_ProductManageType_CName"].ToString()), row["M_ProductManageType_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_CarModel_CName"].ToString()), row["M_CarModel_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_Product_CName"].ToString()), row["M_Product_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_ModelType_CName"].ToString()), row["M_ModelType_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Quantity"].ToString()), row["Quantity"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["RepairProcess"].ToString()), row["RepairProcess"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Kilometers"].ToString()), row["Kilometers"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["ResponseLevel"].ToString()), row["ResponseLevel"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["OccurTimes"].ToString()), row["OccurTimes"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["FeedBackProperty"].ToString()), row["FeedBackProperty"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_UsuallyPart_CName"].ToString()), row["M_UsuallyPart_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["M_UsuallyFault_CName"].ToString()), row["M_UsuallyFault_CName"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["ExectueResult"].ToString()), row["ExectueResult"].ToString()); sbHtml.AppendFormat("<td style='width:{0}'>{1}</td>", HtmlContentWidth(row["Perenct"].ToString()), row["Perenct"].ToString()); sbHtml.AppendLine("</tr>"); iNo++; } sbHtml.AppendLine("</table></div></div>"); return sbHtml.ToString(); } /// <summary> /// 生成Grid标题 /// </summary> /// <param name="strSheetName">表单名称</param> /// <param name="strTitles">Grid标题名称</param> /// <returns>拼接字符串</returns> private static StringBuilder DataGridTitle(string strSheetName, string[] strTitles) { StringBuilder sbHtml=new StringBuilder (); sbHtml.AppendLine("<div class=\"main\">"); sbHtml.AppendFormat("<h2>{0}</h2>", strSheetName); sbHtml.AppendLine("<a href=\"javascript:void(0)\" id=\"closeBtn\" class=\"closeBtn\">关闭</a>"); sbHtml.AppendLine("<div class=\"divOverFlow\">"); sbHtml.AppendFormat("<table class=\"GridTable\" style=\"min-width:{0}\">", HtmlTableWidth(strTitles)); sbHtml.AppendLine("<tr>"); foreach (var title in strTitles) { sbHtml.AppendFormat("<th width={0}>{1}</th>", HtmlTitleWidth(title), title); } sbHtml.AppendLine("</tr>"); return sbHtml; } /// <summary> /// 计算Table的总长度 /// </summary> /// <param name="strTitles">标题数组</param> /// <returns></returns> private static string HtmlTableWidth(string[] strTitles) { string strResult = string.Empty; int nWidth = 0; foreach (var title in strTitles) { nWidth += title.Length * 25; } if (nWidth < 820) { nWidth = 820; } return strResult = nWidth + "px;"; } /// <summary> /// 根据不同内容,计算出标题宽度 /// </summary> /// <param name="strContent">标题</param> /// <returns>宽度</returns> private static string HtmlTitleWidth(string strTitle) { string strResult = string.Empty; strResult = strTitle.Length * 17 + "px"; return strResult; } /// <summary> /// 根据不同内容,计算出内容宽度 /// </summary> /// <param name="strContent">内容</param> /// <returns>宽度</returns> private static string HtmlContentWidth(string strContent) { string strResult = string.Empty; int nWidth = 0; // 判断是否是汉字 for (int i = 0; i < strContent.Length; i++) { // 如果是汉字的情况下,长度设置为 if ((int)strContent > 127) { nWidth += 14; } else { nWidth += 10; } } strResult = nWidth + "px"; return strResult; } } } ------------------------------------------------------------------------------------ CSSCommonHandler.ashx <%@ WebHandler Language="C#" Class="OThinker.H3.Portal.CSSCommonHandler" %> using System; using System.Web; using System.Web.Script.Serialization; using System.Data; using Newtonsoft.Json; using System.Collections.Generic; namespace OThinker.H3.Portal { public class CSSCommonHandler : IHttpHandler { /// <summary> /// 定义HttpContent请求 /// </summary> public HttpContext Context { get; set; } /// <summary> /// /// </summary> /// <param name="context"></param> public void ProcessRequest(HttpContext context) { Context = context; var method = context.Request["method"]; if (method.Length > 0) { var methodInfo = this.GetType().GetMethod(method); if (methodInfo != null) { object obj = methodInfo.Invoke(this, null); if (obj != null) { context.Response.Write(obj.ToString()); } } else { context.Response.Clear(); context.Response.Write("无效的后台方法"); context.Response.End(); context.Response.Flush(); } } else { context.Response.Clear(); context.Response.Write("无效的后台方法"); context.Response.End(); context.Response.Flush(); } } /// <summary> /// /// </summary> public bool IsReusable { get { return false; } } /// <summary> /// 查询产品子表信息 /// </summary> public void QuerySubTableInfo() { string strResult = ""; HttpRequest resquest = Context.Request; string strObjectID = resquest["ObjectID"].ToString(); string loc = resquest["loc"].ToString(); // 根据ObjectID获取产品信息 switch (loc) { case "Customer_GeneralInfo": strResult = CustomerClass.QuerySubProductInfo(strObjectID); break; case "Stock_InStorage": strResult = StoreClass.QuerySubInStorageInfo(strObjectID); break; case "Stock_Allocation": strResult = StoreClass.QuerySubAllocationInfo(strObjectID); break; case "Stock_OutStorage": strResult = StoreClass.QuerySubOutStorageInfo(strObjectID); break; case "Stock_ToolManage": strResult = StoreClass.QuerySubToolManage(strObjectID); break; case "Daily_WorkReport": strResult = WorkReportClass.QueryWorkReportInfo(strObjectID); break; case "Daily_BrakeChangeRecord": strResult = WorkReportClass.QueryBrakeChangeRecordInfo(strObjectID); break; default: break; } // 封装List IList<object> list = new List<object>() { strResult }; // 对List进行序列化返回前端 Context.Response.Write(JSSerializer.Serialize(list)); } /// <summary> /// 查看变更历史记录信息 /// </summary> public void QueryHistoryRecordCode() { string strResult = ""; HttpRequest resquest = Context.Request; string strObjectID = resquest["ObjectID"].ToString(); // 根据ObjectID获取变更历史记录信息 strResult = ProcessClass.QueryHistoryRecordCodeInfo(strObjectID); if (string.IsNullOrEmpty(strResult)) { Context.Response.Write(JSSerializer.Serialize(new List<object>())); } else { // 封装List IList<object> list = new List<object>() { strResult }; // 对List进行序列化返回前端 Context.Response.Write(JSSerializer.Serialize(list)); } } private JavaScriptSerializer _JsSerializer = null; /// <summary> /// 获取JS序列化对象 /// </summary> private JavaScriptSerializer JSSerializer { get { if (_JsSerializer == null) { _JsSerializer = new JavaScriptSerializer(); } return _JsSerializer; } } } } ----------------------------------------------------------------------------- CustomerClass.cs using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; namespace OThinker.H3.Portal { /// <summary> /// CustomerClass 的摘要说明 /// </summary> public class CustomerClass { public CustomerClass() { // // TODO: 在此处添加构造函数逻辑 // } /// <summary> /// 查询产品信息子表 /// </summary> /// <param name="strObjectID">客户基本信息ID</param> /// <returns>查询产品信息子表</returns> public static string QuerySubProductInfo(string strObjectID) { string strSql = string.Empty; strSql = string.Format("select M_ProductManageType_CName,M_CarModel_CName,M_ModelType_CName,M_Product_CName from I_CSS_C_ProductInfo where ParentObjectID='{0}'", strObjectID); // 查询客户产品信息数据 DataTable dt = MMSHFunction.ExecuteTableSql(strSql); // 根据查询信息,转换为Html代码,传入前台 return CSSCommon.SpellSubProductInfo(dt); } } } ---------------------------------------------------------------------------------- 如果大家有什么不明白的,可以qq联系我。 |
|
2楼#
发布于:2016-07-13 14:31
满满的干货啊,有需要的赶紧拿去!
|
|
|
3楼#
发布于:2016-07-13 14:32
楼主,留下你的QQ号再走,如果不介意密码也可同时留下,
|
|
|
4楼#
发布于:2016-07-13 18:51
虽然我不知道你是谁,但我知道你肯定对H3 BPM 运用很精通,高手呀,感谢楼主的知识分享
|
|
5楼#
发布于:2017-05-27 11:26
楼主,问下 DataTable dt = MMSHFunction.ExecuteTableSql(strSql); 中MMSHFunction这个方法你是自己写的吗,能把这个方法贴出来一下吗,感谢,不知道怎么样调用H3自带的方法执行SQL语句
|
|
|
6楼#
发布于:2017-06-01 08:40
受教了
|
|
|