(1) 显示日期 DateTime.Now.ToString("yyyyMMdd") 显示时间 DateTime.Now.ToString("hhmmssff") (2)使用枚举 ,natural,lose,freeze,logout,BeforeDate} if ((IC_CardType)dr_Result["CardType"]!=IC_CardType.fixCard) } 以上枚举使用的的一个用例(3)字符串换行 MessageBox.Show("aaaa" + Environment.NewLine + "bbbb"); (4)线程使用举例:类里面定义了一个私有线程 //线程,用于接收报文 Thread t_ListenPort1; 在窗体的Load事件写入如下代码: t_ListenPort1=new Thread(new ThreadStart(ListenPort)); t_ListenPort1.Start(); 其中ListenPort的定义如下: } 可以自己来写方法Recive_BLCM02()和Recive_BLCR02()(5)读取配置文件指定的信息配置文件App.Config格式如下: <configuration> <!-- 错误捕捉日志--> <configSections> <section name="exceptionManagement" type="OceanSoft.DevFramework.Common.ExceptionManagement.ExceptionManagerSectionHandler,OceanSoft.DevFramework.Common" /> </configSections> <!--mode="on"记录异常信息mode="off"不记录异常信息--> <exceptionManagement mode="on"> <publisher assembly="OceanSoft.DevFramework.Common" type="OceanSoft.DevFramework.Common.ExceptionManagement.ExceptionPublisher" exclude="*" include="OceanSoft.DevFramework.Common.MyException, OceanSoft.DevFramework.Common" /> </exceptionManagement> <startup> <supportedRuntime version="v1.1.4322" /> <requiredRuntime version="v1.1.4322" safemode="true" /> </startup> <appSettings> <add key="StationProgram" value="D:\Program Files\Eclipse\eclipse.exe" /> <add key="barMainToolbar.Visible" value="True" /> <add key="FTPHost" value="172.17.100.85" /> <add key="FTPPort" value="21" /> <add key="FTPUser" value="logerp" /> <add key="FtpPass" value="logerp@oceansoft" /> <add key="SenderID" value="0003713" /> <add key="ReceiverID" value="0003714" /> <add key="BLC302Dir" value="BLC302/" /> <add key="BLC304Dir" value="BLC304/" /> <add key="BLC305Dir" value="BLC305/" /> <add key="BLC306Dir" value="BLC306/" /> <!--异常监控通道1--> <add key="Channel1" value="0001" /> <!--异常监控通道2--> <add key="Channel2" value="0002" /> <!--设备控制窗体刷新时间间隔 单位分钟--> <add key="TimeInterval" value="5"/> </appSettings></configuration> 首先使用引用,如下: using System.Configuration; 读取相关配置信息如下: //根据通道编号决定显示位置 string str_channel1 = ConfigurationSettings.AppSettings["channel1"]; string str_channel2 = ConfigurationSettings.AppSettings["channel2"]; (6)根据线程当前状态关闭线程 //窗体关闭的时候关闭线程 if (t_ListenPort1.ThreadState == ThreadState.Running) } 窗体关闭的时候线程关闭 foreach(Thread t in threadHolder.Values) Form1.ActiveForm.Close(); (7)对已经存在的DataTable 里面新增加列 Condition pobj_Con = new Condition(); pobj_Con.Add("SQL", str_Sql); DataTable dt = this.Search("LOGERP_ASSET_Asset_SEL_20050830124902", pobj_Con).Tables[0]; //this.Alert(dt.Rows.Count.ToString()); DataColumn ChannelState = new DataColumn(); ChannelState.DataType = System.Type.GetType("System.String"); ChannelState.ColumnName = "ChannelState"; ChannelState.DefaultValue = ""; dt.Columns.Add(ChannelState); 最重要的是最后的5行 相关文章: