界面虽然被我弄的很难看,但功能还可以
里边注册表的路径自己设置一下,或者加一个创建注册表的语句,不然会报错
前台:
Html代码
class="star" src="/Upload/Images/2014070417/40B102E0EF997EA6.png" alt="收藏代码" />
- <%@ Page Language="C#" AutoEventWireup="true" CodeFile="FPSZ.aspx.cs" Inherits="_Default" %>
-
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
- <script language="JavaScript" type="text/javascript" src="js/Move.js"></script>
-
- <script language="JavaScript" type="text/javascript" src="js/preview.js"></script>
-
- <html xmlns="http://www.w3.org/1999/xhtml" >
- <head runat="server">
- <title>无标题页</title>
- </head>
- <body>
- <form id="form1" runat="server">
-
-
-
-
-
- <div>
- <div>
- <table width = "100%">
- <tr>
- <td>
- <table width = "100%">
- <tr>
- <td>
- <asp:Panel ID = "pnlFPSZ" BorderWidth = "1" Width = "100%" runat = "server">
- <table width = "100%">
- <tr>
- <td>
- <table width = "100%">
- <tr>
- <td style="height: 96px">
- <table width = "100%">
- <tr>
- <td>
- <asp:Label ID = "lblTKRQ" Text = "黑色头发:" runat = "server" Font-Underline = "true"></asp:Label>
- </td>
- <td>
- <asp:Label ID = "lblTKRQText" Text = "黑色头发" runat = "server" name="label" BackColor="silver" Style="left: 335px; position: absolute;top: 179px" onclick="getID('lblTKRQText')" Width="50"></asp:Label>
- <asp:HiddenField ID="lblTKRQText_hdl_Top" runat="server" Value="" />
- <asp:HiddenField ID="lblTKRQText_hdl_Left" runat="server" Value="" />
-
- </td>
- </tr>
- </table>
- </td>
- <td style="height: 96px">
- <table width = "100%">
- <tr>
- <td>
- <asp:Label ID = "lblMC" Text = "紫色头发" runat = "server" name="label" BackColor="silver" Style="left: 500px; position: absolute;top: 179px" onclick="getID('lblMC')" Width="50"></asp:Label>
- <asp:HiddenField ID="lblMC_hdl_Top" runat="server" Value="" />
- <asp:HiddenField ID="lblMC_hdl_Left" runat="server" Value="" />
-
- </td>
- </tr>
- </table>
- </td>
- </tr>
- <tr>
- <td colspan = "1" style="height: 340px">
- <table width = "100%" border = "3">
- <tr>
- <td style="width: 155px">
- <asp:Label ID = "lblJKDW_XM" Text = "黑色头发紫色头发" runat = "server" Font-Underline = "true"></asp:Label>
- </td>
- <td style="height: 41px">
- <asp:Label ID = "lblJKDW_XMText" Text = "黑紫色头发" runat = "server" name="label" BackColor="silver" Style="left: 450px; position: absolute;top: 272px" onclick="getID('lblJKDW_XMText')" Width="37"></asp:Label>
- <asp:HiddenField ID="lblJKDW_XMText_hdl_Top" runat="server" Value="" />
- <asp:HiddenField ID="lblJKDW_XMText_hdl_Left" runat="server" Value="" />
-
- </td>
- <td style="height: 41px">
- <table width = "100%" border = "3">
- <tr>
- <td>
- <asp:Label ID = "lblJKFS" Text = "北京市" runat = "server" Font-Underline = "true"></asp:Label>
- </td>
- <td>
-
-
- <asp:Label ID = "lblJKFSText" Text = "北京市" runat = "server" Font-Underline="True" name="label" BackColor="silver" Style="left: 850px; position: absolute;top: 274px" onclick="getID('lblJKFSText')" Width="27"></asp:Label>
- <asp:HiddenField ID="lblJKFSText_hdl_Top" runat="server" Value="" />
- <asp:HiddenField ID="lblJKFSText_hdl_Left" runat="server" Value="" />
-
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </asp:Panel>
- </td>
- </tr>
- </table>
- </td>
- </tr>
- </table>
- </div>
- <br />
- <div>
- <table width = "100%">
- <tr>
- <td style="width: 104px">
- <asp:Label ID = "lblDQDYJ" Text = "当前打印机" runat = "server"></asp:Label></td>
- <td style="width: 175px">
- <asp:DropDownList ID = "ddlDYJ" runat = "server" Width="169px"></asp:DropDownList>
- </td>
- <td>
- <input id="ibnSY" runat="server" type="button" value="上移" onclick="moveTop()" />
- </td>
- <td>
- <input id="ibnXY" runat="server" type="button" value="下移" onclick="moveUnder()" />
- </td>
- <td>
- <input id="ibnZY" runat="server" type="button" value="左移" onclick="moveLeft()" />
- </td>
- <td>
- <input id="ibnYY" runat="server" type="button" value="右移" onclick="moveRight()" />
- </td>
- </tr>
- <tr>
- <td colspan = "2">
- </td>
- <td>
- <asp:Button ID = "ibnBC" Text = "保存" runat = "server" Visible=true OnClick="ibnBC_Click" />
- </td>
- <td>
- <asp:Button ID = "ibnDY" Text = "普通打印" runat = "server" OnClick="ibnDY_Click" />
- </td>
- <td colspan = "2">
- </td>
- </tr>
- </table>
- </div>
- </div>
-
- <input type="button" name="print" value="预览并打印" onclick="preview()">
-
-
- </form>
- </body>
- </html>
后台:
C#代码
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
-
-
- using System.Collections;
-
- public partial class _Default : System.Web.UI.Page
- {
- Helper app_Helper = new Helper();
-
- ArrayList al_DZ = new ArrayList();
-
- string str_BL = "";
-
- Hashtable htbl = new Hashtable();
-
- Hashtable htbl_Read = new Hashtable();
-
- QuickTest qt = new QuickTest();
-
- protected void Page_Load(object sender, EventArgs e)
- {
- if (!IsPostBack)
- {
- GetControls(this);
-
- string[] print = qt.EnumeratePrintersWin();
-
- ddlDYJ.Items.Insert(0, "--请选择打印机--");
-
- for (int i = 0; i < print.Length; i++)
- {
- ddlDYJ.Items.Insert(i + 1, print[i]);
- }
- }
- }
-
- #region 提取注册表中节点为BS_EMSYJKDSZ下所有值,赋给Label控件样式
-
- private void GetControls(Control c)
- {
- if (c is Label)
- {
- htbl_Read = app_Helper.get_regist_value("BS_FPSZ");
-
- foreach (DictionaryEntry die in htbl_Read)
- {
- string writeKey = die.Key.ToString();
-
- Hashtable writeStr = (Hashtable)die.Value;
-
- string top_In = "";
- string left_In = "";
-
- foreach (DictionaryEntry die_In in writeStr)
- {
- string writeKey_In = die_In.Key.ToString();
-
- string writeStr_In = die_In.Value.ToString();
-
- if (writeKey_In.Equals("Top"))
- {
- top_In = writeStr_In;
- }
- if (writeKey_In.Equals("Left"))
- {
- left_In = writeStr_In;
- }
- if (!top_In.Equals("") && !left_In.Equals(""))
- {
- if (c.ID.Equals(writeKey))
- {
- ((Label)c).Style["Style"] = "position: absolute;top:" + top_In + ";left:" + left_In + "";
- }
- }
- }
- }
- }
- if (c.HasControls())
- {
- foreach (Control con in c.Controls)
- {
- GetControls(con);
- }
- }
- }
-
- #endregion 提取注册表中节点为BS_EMSYJKDSZ下所有值,赋给Label控件样式
-
- #region 打印
-
- protected void ibnDY_Click(object sender, EventArgs e)
- {
- ibnDY.Attributes.Add("OnClick", "window.print()");
- }
-
- #endregion 打印
-
- #region 保存
-
- protected void ibnBC_Click(object sender, EventArgs e)
- {
- al_DZ.Add("BS_FPSZ");
-
-
- string lblTKRQText_Left = "";
- string lblTKRQText_Top = "";
-
- if (lblTKRQText_hdl_Left.Value.Equals(""))
- {
- lblTKRQText_Left = lblTKRQText.Style["left"];
- }
- else
- {
- lblTKRQText_Left = lblTKRQText_hdl_Left.Value;
- }
- if (lblTKRQText_hdl_Top.Value.Equals(""))
- {
- lblTKRQText_Top = lblTKRQText.Style["top"];
- }
- else
- {
- lblTKRQText_Top = lblTKRQText_hdl_Top.Value;
- }
-
- str_BL = "lblTKRQText";
- htbl.Add("FontBold", "false");
- htbl.Add("FontName", "宋体");
- htbl.Add("FontSize", "9");
- htbl.Add("Left", lblTKRQText_Left);
- htbl.Add("Top", lblTKRQText_Top);
- app_Helper.registWrite(al_DZ, str_BL, htbl);
-
-
-
- string lblMC_Left = "";
- string lblMC_Top = "";
-
- if (lblMC_hdl_Left.Value.Equals(""))
- {
- lblMC_Left = lblMC.Style["left"];
- }
- else
- {
- lblMC_Left = lblMC_hdl_Left.Value;
- }
- if (lblMC_hdl_Top.Value.Equals(""))
- {
- lblMC_Top = lblMC.Style["top"];
- }
- else
- {
- lblMC_Top = lblMC_hdl_Top.Value;
- }
-
- str_BL = "lblMC";
- htbl.Clear();
- htbl.Add("FontBold", "false");
- htbl.Add("FontName", "宋体");
- htbl.Add("FontSize", "9");
- htbl.Add("Left", lblMC_Left);
- htbl.Add("Top", lblMC_Top);
- app_Helper.registWrite(al_DZ, str_BL, htbl);
-
-
-
- string lblJKDW_XMText_Left = "";
- string lblJKDW_XMText_Top = "";
-
- if (lblJKDW_XMText_hdl_Left.Value.Equals(""))
- {
- lblJKDW_XMText_Left = lblJKDW_XMText.Style["left"];
- }
- else
- {
- lblJKDW_XMText_Left = lblJKDW_XMText_hdl_Left.Value;
- }
- if (lblJKDW_XMText_hdl_Top.Value.Equals(""))
- {
- lblJKDW_XMText_Top = lblJKDW_XMText.Style["top"];
- }
- else
- {
- lblJKDW_XMText_Top = lblJKDW_XMText_hdl_Top.Value;
- }
-
- str_BL = "lblJKDW_XMText";
- htbl.Clear();
- htbl.Add("FontBold", "false");
- htbl.Add("FontName", "宋体");
- htbl.Add("FontSize", "9");
- htbl.Add("Left", lblJKDW_XMText_Left);
- htbl.Add("Top", lblJKDW_XMText_Top);
- app_Helper.registWrite(al_DZ, str_BL, htbl);
-
-
-
- string lblJKFSText_Left = "";
- string lblJKFSText_Top = "";
-
- if (lblJKFSText_hdl_Left.Value.Equals(""))
- {
- lblJKFSText_Left = lblJKFSText.Style["left"];
- }
- else
- {
- lblJKFSText_Left = lblJKFSText_hdl_Left.Value;
- }
- if (lblJKFSText_hdl_Top.Value.Equals(""))
- {
- lblJKFSText_Top = lblJKFSText.Style["top"];
- }
- else
- {
- lblJKFSText_Top = lblJKFSText_hdl_Top.Value;
- }
-
- str_BL = "lblJKFSText";
- htbl.Clear();
- htbl.Add("FontBold", "false");
- htbl.Add("FontName", "宋体");
- htbl.Add("FontSize", "9");
- htbl.Add("Left", lblJKFSText_Left);
- htbl.Add("Top", lblJKFSText_Top);
- app_Helper.registWrite(al_DZ, str_BL, htbl);
-
-
-
-
-
- GetControls(this);
- }
-
- #endregion 保存
-
- }
Helper.cs
C#代码
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
-
-
- using System.Text.RegularExpressions;
- using System.Collections;
- using System.Web.Configuration;
- using Microsoft.Win32;
- using System.IO;
- using System.Drawing;
-
- using System.Runtime.InteropServices;
- using System.Drawing.Imaging;
-
- public class Helper
- {
- public Helper()
- {
-
-
-
- }
-
- #region 注册表
-
-
-
-
-
-
- public Hashtable get_regist_value(string readKey)
- {
- Hashtable registHtbl = new Hashtable();
-
- RegistryKey hkml = Registry.Users;
-
-
-
-
- RegistryKey aimdir = hkml.OpenSubKey("S-1-5-21-1177238915-527237240-1801674531-1013\\Asp Net Settings", true);
- RegistryKey aimdirs = aimdir.OpenSubKey("zldzjc", true);
- RegistryKey aimdirss = aimdirs.CreateSubKey(readKey);
-
- if (aimdirss.SubKeyCount != 0)
- {
- foreach (string subKeyName in aimdirss.GetSubKeyNames())
- {
- Hashtable registSubHtbl = new Hashtable();
-
- RegistryKey aimdirsss = aimdirss.CreateSubKey(subKeyName);
-
- foreach (string subValueName in aimdirsss.GetValueNames())
- {
- string aaa = aimdirsss.GetValue(subValueName).ToString();
-
- registSubHtbl.Add(subValueName, aaa);
-
-
- }
-
- registHtbl.Add(subKeyName, registSubHtbl);
-
-
- }
- }
-
- hkml.Close();
-
- aimdirs.Close();
- aimdirss.Close();
-
- return registHtbl;
- }
-
-
-
-
-
-
-
- public void registWrite(ArrayList al_subKeyed, string al_subKeying, Hashtable htbl)
- {
- RegistryKey hkml = Registry.CurrentUser;
-
-
-
- RegistryKey aimdir = hkml.OpenSubKey("S-1-5-21-1177238915-527237240-1801674531-1013\\Asp Net Settings", true);
- RegistryKey aimdirs = aimdir.OpenSubKey("zldzjc", true);
-
- for (int i = 0; i < al_subKeyed.Count; i++)
- aimdirs = aimdirs.CreateSubKey(al_subKeyed[i].ToString());
-
-
- RegistryKey open = aimdirs.CreateSubKey(al_subKeying);
-
- foreach (DictionaryEntry die in htbl)
- {
- string writeKey = die.Key.ToString();
- string writeStr = die.Value.ToString();
-
- open.SetValue(writeKey, writeStr);
- }
-
-
-
- hkml.Close();
-
-
- aimdir.Close();
- aimdirs.Close();
- }
-
- #endregion 注册表
-
- }
QuickTest.cs
C#代码
- using System;
- using System.Data;
- using System.Configuration;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.WebControls.WebParts;
- using System.Web.UI.HtmlControls;
-
- using System.Collections;
-
- using System.Runtime.InteropServices;
-
- using System.Diagnostics;
-
- using System.Drawing.Printing;
-
- public class QuickTest
- {
- [DllImport("winspool.drv", CharSet = CharSet.Auto)]
-
- static extern bool EnumPrinters(int flags, string name, int level, IntPtr pPrinterEnum,
-
- int cbBuf, out int pcbNeeded, out int pcReturned);
-
- private const int PRINTER_ENUM_NETWORK = 0x00000040;
-
- private const int PRINTER_ENUM_LOCAL = 0x00000002;
-
- private const int PRINTER_ENUM_REMOTE = 0x00000010;
-
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
-
- struct PRINTER_INFO_1
- {
-
- int flags;
-
- [MarshalAs(UnmanagedType.LPTStr)]
-
- public string pDescription;
-
- [MarshalAs(UnmanagedType.LPTStr)]
-
- public string pName;
-
- [MarshalAs(UnmanagedType.LPTStr)]
-
- public string pComment;
-
- }
-
- public string[] EnumeratePrintersWin()
- {
- string[] print_All = null;
-
- bool Success;
-
- int cbRequired;
-
- int nEntries;
-
- IntPtr outb = IntPtr.Zero;
-
- Success = EnumPrinters(PRINTER_ENUM_NETWORK | PRINTER_ENUM_LOCAL | PRINTER_ENUM_REMOTE, null, 1, outb, 0, out cbRequired, out nEntries);
-
- outb = Marshal.AllocHGlobal(cbRequired);
-
- Success = EnumPrinters(PRINTER_ENUM_NETWORK | PRINTER_ENUM_LOCAL | PRINTER_ENUM_REMOTE, null, 1, outb, cbRequired, out cbRequired, out nEntries);
-
- PRINTER_INFO_1[] portsArray = new PRINTER_INFO_1[cbRequired];
-
- IntPtr current = outb;
-
- try
- {
- if (nEntries != 0)
- {
- print_All = new string[nEntries];
- }
- else
- {
- print_All = new string[1];
-
- print_All[0] = "null";
-
- return print_All;
- }
-
-
- for (int i = 0; i < nEntries; i++)
- {
- portsArray[i] = (PRINTER_INFO_1)Marshal.PtrToStructure(current,
-
- typeof(PRINTER_INFO_1));
-
- current = (IntPtr)((int)current + Marshal.SizeOf(typeof(PRINTER_INFO_1)));
-
-
-
- print_All[i] = i + ": \n" + portsArray[i].pName + "\n" + portsArray[i].pDescription + "\n" + portsArray[i].pComment + "\n";
-
-
- }
-
- }
-
- catch (Exception exp)
- {
-
- Console.WriteLine(exp.StackTrace);
-
- }
-
- Marshal.FreeHGlobal(outb);
-
- return print_All;
- }
-
- public QuickTest()
- {
-
- }
-
- public static void Main()
- {
-
- QuickTest qt = new QuickTest();
-
- qt.EnumeratePrintersWin();
-
- Console.ReadLine();
- }
-
-
- }
js/Move.js
Js代码
-
-
-
- var labelID = "";
- var hdlID = "";
-
- function moveTop()
- {
- var a=document.getElementById(labelID).style.top;
- var Top=a.substring(0,a.indexOf("px"));
- document.getElementById(labelID).style.top= parseInt(Top)-10;
-
- document.getElementById(labelID+"_hdl_Top").value=document.getElementById(labelID).style.top;
- }
- function moveUnder()
- {
- var aa=document.getElementById(labelID).style.top;
- var Topp=aa.substring(0,aa.indexOf("px"));
- document.getElementById(labelID).style.top= parseInt(Topp)+10;
-
- document.getElementById(labelID+"_hdl_Top").value=document.getElementById(labelID).style.top;
- }
- function moveLeft()
- {
- var b=document.getElementById(labelID).style.left;
- var Left=b.substring(0,b.indexOf("px"));
- document.getElementById(labelID).style.left= parseInt(Left)-10;
-
- document.getElementById(labelID+"_hdl_Left").value=document.getElementById(labelID).style.left;
- }
- function moveRight()
- {
- var bb=document.getElementById(labelID).style.left;
- var Leftt=bb.substring(0,bb.indexOf("px"));
- document.getElementById(labelID).style.left= parseInt(Leftt)+10;
-
- document.getElementById(labelID+"_hdl_Left").value=document.getElementById(labelID).style.left;
- }
- function getID(labelIDCS)
- {
-
-
- labelID = labelIDCS;
-
- var arrAll=document.all;
-
- for(i=0;i <arrAll.length;i++)
- {
- if(arrAll[i].name == 'label')
- {
- document.getElementById(arrAll[i].id).style.color = "black";
- }
- }
- document.getElementById(labelID).style.color = "red";
- }
- function font_Update()
- {
- var arrAll=document.all;
-
- for(i=0;i <arrAll.length;i++)
- {
- if(arrAll[i].name == 'label')
- {
- document.getElementById(arrAll[i].id).style.fontFamily="Times New Roman";
- }
- }
- }
js/preview.js
Js代码
-
-
-
- <!--
- function preview()
- {
- bdhtml=window.document.body.innerHTML;
-
- sprnstr="<!--startprint-->";
- eprnstr="<!--endprint-->";
- prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);
-
- alert("prnhtml:"+prnhtml);
-
- prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));
- window.document.body.innerHTML=prnhtml;
- window.print();
- }
- -->