电梯存档表格怎么做?我是物管的,领导要求一梯一档,求大神支招

电梯存档表格怎么做?我是物管的,领导要求一梯一档,求大神支招,第1张

每台电梯一个档案袋,里面包含电梯保养记录,维修记录,年检合格报告,年检合格证(可复印件),也可有机房巡查记录,应急救援演练等等和电梯相关材料。前两项由电梯维保公司出具,你方签字后存档,档案保存四年以上。

JSP页面中嵌入动态图表的两种方法 :在JSP页面中插入Applet小程序 通过JavaBean动态生成图像。

JSP是一种广泛应用的网页设计技术 ,它是一种HTML和Java脚本混合的编程技术 ,它结合了HTML的静态特性和Java语言的动态能力 ,因此用它进行动态网页设计非常方便。在进行图像处理时 ,一般处理静态图片非常容易 ,但是 ,在实际应用中常常需要动态地在网页中生成二维的图形.

基于JFreeChart开发的一个时序图的绘制。代码如下:

实例中createDataset()方法用于创建数据集合对象。时序图的数据集合与其他数据集合不同,它需要添加一个时间段内的所有数据,通常采用TimeSeries类进行添加。该实例中通过Math类的random()方法进行随机生成。

import java.awt.*

import java.awt.event.ActionEvent

import

java.awt.event.ActionListener

import java.io.BufferedInputStream

import

java.io.DataInputStream

import java.io.FileOutputStream

import

java.io.IOException

import java.net.URL

import

java.net.URLConnection

import java.text.DateFormat

import

java.text.ParseException

import java.text.SimpleDateFormat

import

java.util.Calendar

import java.util.Date

import java.util.Random

import javax.swing.JApplet

import javax.swing.Timer

import org.jfree.chart.*

import

org.jfree.chart.annotations.CategoryTextAnnotation

import

org.jfree.chart.axis.CategoryAnchor

import

org.jfree.chart.axis.CategoryAxis

import

org.jfree.chart.axis.CategoryLabelPositions

import

org.jfree.chart.axis.DateAxis

import

org.jfree.chart.axis.DateTickUnit

import

org.jfree.chart.axis.DateTickUnitType

import

org.jfree.chart.axis.ValueAxis

import

org.jfree.chart.labels.StandardCategoryItemLabelGenerator

import

org.jfree.chart.plot.CategoryPlot

import

org.jfree.chart.plot.PlotOrientation

import

org.jfree.chart.plot.XYPlot

import

org.jfree.chart.renderer.category.BarRenderer

import

org.jfree.chart.title.TextTitle

import

org.jfree.data.category.CategoryDataset

import

org.jfree.data.category.IntervalCategoryDataset

import org.jfree.chart.axis.NumberAxis

import

org.jfree.data.category.DefaultCategoryDataset

import

org.jfree.data.gantt.Task

import org.jfree.data.gantt.TaskSeries

import

org.jfree.data.gantt.TaskSeriesCollection

import

org.jfree.data.time.Day

import org.jfree.data.time.Second

import

org.jfree.data.time.TimeSeries

import

org.jfree.data.time.TimeSeriesCollection

import

org.jfree.data.xy.XYDataset

public class shixutu extends JApplet {

//PLOT_FONT是一静态的字体常量对象,使用此对象可以避免反复用到的字体对象被多次创建

private static final Font PLOT_FONT = new Font("黑体", Font.ITALIC ,

18)

JFreeChart chart

//创建数据动态更新的监听

class DataGenerator extends Timer

implements ActionListener {

private static final long serialVersionUID =

3977867288743720504L

String

equID

//设备ID号

int

totalTask

//任务数

String[][]

strTask

//任务情况

public void

actionPerformed(ActionEvent actionevent) {

addTotalObservation()

} DataGenerator()

{

super(1000,

null)

addActionListener(this)

System.out.println("super")

}

}

//将更新的数据添加到chart中

private void addTotalObservation()

{

System.out.println("addTotalObservation")

//设置新的数据集

chart.getXYPlot().setDataset(createDataset())

//通知Jfreechart

数据发生了改变,重新绘制柱状图

if

(chart != null)

{

chart.fireChartChanged()

}

}

private static void

processChart(JFreeChart chart)

{

//设置标题字体

chart.getTitle().setFont(new Font("隶书", Font.BOLD,

26))

//设置背景色

chart.setBackgroundPaint(new

Color(252,175,134))

XYPlot plot = chart.getXYPlot()

//获取图表的绘制属性

plot.setDomainGridlinesVisible(false)

//设置网格不显示

//获取时间轴对象

DateAxis dateAxis = (DateAxis)

plot.getDomainAxis()

dateAxis.setLabelFont(PLOT_FONT)

//设置时间轴字体

//设置时间轴标尺值字体

dateAxis.setTickLabelFont(new

Font("宋体",Font.PLAIN,12))

dateAxis.setLowerMargin(0.0)

//设置时间轴上显示的最小值

//获取数据轴对象

ValueAxis valueAxis =

plot.getRangeAxis()

valueAxis.setLabelFont(PLOT_FONT)

//设置数据字体

DateFormat format = new SimpleDateFormat("mm分ss秒")

//创建日期格式对象

//创建DateTickUnit对象

DateTickUnit dtu = new

DateTickUnit(DateTickUnitType.SECOND,30,format)

dateAxis.setTickUnit(dtu)

//设置日期轴的日期标签 } //将结果输出在文件中

private static

void writeChartAsImage(JFreeChart chart)

{

FileOutputStream fos_jpg =

null

try

{

fos_jpg = new

FileOutputStream("D:\\test\\shixutu.jpg")

ChartUtilities.writeChartAsJPEG(fos_jpg, 1, chart, 400, 300,

null)

} catch (Exception e)

{

e.printStackTrace()

} finally

{

try

{

fos_jpg.close()

} catch (Exception e)

{

}

}

}

//创建数据集合对象

public static XYDataset createDataset()

{

//实例化TimeSeries对象

TimeSeries timeseries = new

TimeSeries("Data")

Second second = new Second()

//实例化Day

double d =

50D

//添加一年365天的数据

for (int i = 0i <500i++)

{

d = d + (Math.random() - 0.5) * 10

//创建随机数据

timeseries.second(day, d)

//向数据集合中添加数据

second = (Second)

second.next()

}

TimeSeriesCollection timeSeriesCollection =

new

TimeSeriesCollection(timeseries)

//返回数据集合对象

return timeSeriesCollection } //Applet程序初始化

public void init()

{

// 1.

得到数据

XYDataset dataset =

createDataset()

// 2.

构造chart

chart =

ChartFactory.createTimeSeriesChart(

"时序图示范", //

图表标题

"时间", //

目录轴的显示标签--横轴

"数值", //

数值轴的显示标签--纵轴

dataset, //

数据集

false,

false, //

是否生成工具

false //

是否生成URL链接

)

// 3.

处理chart中文显示问题

processChart(chart)

// 4.

chart输出图片

//writeChartAsImage(chart)

// 5. chart

以swing形式输出

//6.使用applet输出

ChartPanel chartPanel = new

ChartPanel(chart)

chartPanel.setPreferredSize(new

java.awt.Dimension(800,500))

getContentPane().add(chartPanel) (new

DataGenerator()).start()

}

public void

paint(Graphics g)

{

if

(chart != null)

{

chart.draw((Graphics2D) g,

getBounds())

}

}

public void destroy() {

}

}

第一步,我先从简单的调用出发,定义了一个简单的函数,该函数仅仅实现一个整数加法求和:

LIBEXPORT_API int mySum(int a,int b){ return a+b}

C# 导入定义:

public class RefComm

{

[DllImport("LibEncrypt.dll",

EntryPoint=" mySum ",

CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]

public static extern int mySum (int a,int b)

}

在C#中调用测试:

int iSum = RefComm.mySum(,)

运行查看结果iSum为5,调用正确。第一步试验完成,说明在C#中能够调用自定义的动态链接库函数。

第二步,我定义了字符串 *** 作的函数(简单起见,还是采用前面的函数名),返回结果为字符串:

LIBEXPORT_API char *mySum(char *a,char *b){sprintf(b,"%s",a)return a}

C# 导入定义:

public class RefComm

{

[DllImport("LibEncrypt.dll",

EntryPoint=" mySum ",

CharSet=CharSet.Auto,

CallingConvention=CallingConvention.StdCall)]

public static extern string mySum (string a, string b)

}

在C#中调用测试:

string strDest=""

string strTmp= RefComm.mySum("45", strDest)

运行查看结果 strTmp 为"45",但是strDest为空。我修改动态链接库实现,返回结果为串b:

LIBEXPORT_API char *mySum(char *a,char *b){sprintf(b,"%s",a) return b}

修改 C# 导入定义,将串b修改为ref方式:

public class RefComm

{

[DllImport("LibEncrypt.dll",

EntryPoint=" mySum ",

CharSet=CharSet.Auto,CallingConvention=CallingConvention.StdCall)]

public static extern string mySum (string a, ref string b)

}

在C#中再调用测试:

string strDest=""

string strTmp= RefComm.mySum("45", ref strDest)

运行查看结果 strTmp 和 strDest 均不对,含不可见字符。再修改 C# 导入定义,将CharSet从Auto修改为Ansi:

public class RefComm

{

[DllImport("LibEncrypt.dll",

EntryPoint=" mySum ",

CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]

public static extern string mySum (string a, string b)

}

在C#中再调用测试:

string strDest=""

string strTmp= RefComm. mySum("45", ref strDest)

运行查看结果 strTmp 为"45",但是串 strDest 没有赋值。第二步实现函数返回串,但是在函数出口参数中没能进行输出。再次修改 C# 导入定义,将串b修改为引用(ref):

public class RefComm

{

[DllImport("LibEncrypt.dll",

EntryPoint=" mySum ",

CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]

public static extern string mySum (string a, ref string b)

}

运行时调用失败,不能继续执行。

第三步,修改动态链接库实现,将b修改为双重指针:

LIBEXPORT_API char *mySum(char *a,char **b){sprintf((*b),"%s",a)return *b}

C#导入定义:

public class RefComm

{

[DllImport("LibEncrypt.dll",

EntryPoint=" mySum ",

CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]

public static extern string mySum (string a, ref string b)

}

在C#中调用测试:

string strDest=""

string strTmp= RefComm. mySum("45", ref strDest)

运行查看结果 strTmp 和 strDest 均为"45",调用正确。第三步实现了函数出口参数正确输出结果。

第四步,修改动态链接库实现,实现整数参数的输出:

LIBEXPORT_API int mySum(int a,int b,int *c){ *c=a+breturn *c}

C#导入的定义:

public class RefComm

{

[DllImport("LibEncrypt.dll",

EntryPoint=" mySum ",

CharSet=CharSet.Ansi,CallingConvention=CallingConvention.StdCall)]

public static extern int mySum (int a, int b,ref int c)

}

在C#中调用测试:

int c=0

int iSum= RefComm. mySum(,, ref c)

运行查看结果iSum 和c均为5,调用正确。

经过以上几个步骤的试验,基本掌握了如何定义动态库函数以及如何在 C# 定义导入,有此基础,很快我实现了变长加密函数在 C# 中的调用,至此目标实现。

三、结论

在 C# 中调用 C++ 编写的动态链接库函数,如果需要出口参数输出,则需要使用指针,对于字符串,则需要使用双重指针,对于 C# 的导入定义,则需要使用引用(ref)定义。

对于函数返回值,C# 导入定义和 C++ 动态库函数声明定义需要保持一致,否则会出现函数调用失败。定义导入时,一定注意 CharSet 和 CallingConvention 参数,否则导致调用失败或结果异常。运行时,动态链接库放在 C# 程序的目录下即可,我这里是一个 C# 的动态链接库,两个动态链接库就在同一个目录下运行。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/sjk/10044823.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-04
下一篇2023-05-04

发表评论

登录后才能评论

评论列表(0条)

    保存