.net 生成excle

Protected Sub Button_excel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_excel.Click

        Dim sql_string As String = "select * from smt_time_List where 1=1 "

        If Me.TextBox_model.Text.Trim <> "" Then
            sql_string = sql_string + " and Model = ‘" + Me.TextBox_model.Text.Trim + "’ "
        End If

        If Me.DropDownList_project.SelectedIndex > 0 Then
            sql_string = sql_string + " and Project = ‘" + Me.DropDownList_project.SelectedValue.Trim + "’ "
        End If

        If Me.TextBox_updatedate.Text.Trim <> "" Then
            sql_string = sql_string + " and Update_Date = ‘" + Me.TextBox_updatedate.Text.Trim + "’ "
        End If

        If Me.DropDownList_line.SelectedIndex > 0 Then
            sql_string = sql_string + "and Line = ‘" + Me.DropDownList_line.SelectedValue.Trim + "’ "
        End If

        If Me.DropDownList_boardsider.SelectedIndex > 0 Then
            sql_string = sql_string + " and Board_Side= ‘" + Me.DropDownList_boardsider.SelectedValue.Trim + "’ "
        End If

        If Me.DropDownList_owner.SelectedIndex > 0 Then
            sql_string = sql_string + " and Owner = ‘" + Me.DropDownList_owner.SelectedValue.Trim + "’"
        End If

        Myconnection.Open()
        Dim myds As New DataSet
        Dim myad As New SqlDataAdapter(sql_string, Myconnection)
        myad.Fill(myds)

        ‘write excel******************************************

        ‘*************************************************************
        Dim sHtml As String
        sHtml = "<table cellSpacing=’0′ borderColorDark=’#ffffff’ cellPadding=’0′ width=’100%’ border=’1′>"
        sHtml = sHtml & "<tr bgColor=’#CCFFFF’><STRONG><td colspan=’1′ >Project</td><td colspan=’1′ >BU</td><td colspan=’1′ >Model</td><td colspan=’1′ >Description</td><td colspan=’1′ >Rev</td><td colspan=’1′ >Board_Side</td><td colspan=’1′ >Line</td><td colspan=’1′ >Quotation_Time</td><td colspan=’1′ >Standard_time</td><td colspan=’1′ >Update_Date</td><td colspan=’1′ >Owner</td></STRONG></tr>"
        For i As Integer = 0 To myds.Tables(0).Rows.Count – 1
            sHtml = sHtml & "<tr><STRONG><td >" & myds.Tables(0).Rows(i).Item("Project").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("BU").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("Model").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("Description").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("Rev").ToString & "</td><td>" & myds.Tables(0).Rows(i).Item("Board_Side").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Line").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Quotation_Time").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Standard_time").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Update_Date").ToString & "</td><td >" & myds.Tables(0).Rows(i).Item("Owner").ToString & "</td></STRONG></tr>"
        Next
        sHtml = sHtml & "</table>"
        Dim urlstr As String

        urlstr = MapPath(Request.ApplicationPath) + "xlssmt_std_report.xls"

 

        Dim fileWrite As StreamWriter = New StreamWriter(urlstr, False, Encoding.Default)     ‘Encoding.UTF8)
        fileWrite.Write(sHtml)
        fileWrite.Close()
        fileWrite.Dispose()
        Response.Write("<script>window.open(‘" + Request.ApplicationPath + "/xls/smt_std_report.xls" + "’);</script>")

    End Sub

搬家了

经过一番折腾,终于把博客搬到了好友Troy的服务器上。

以前买的100M的虚拟主机,结果,因为放了两个视频文件,现在博客文件已经达到150M。也不能升级,只好想办法搬家。

感谢Troy,感谢Z-Blog的程序,感谢所有关注我Blog的网友,在今后的日子里,我将重新开始,重新回到以前的生活,让自己充满斗志,为了生活去奋斗。

在过去这段灰暗的日子里,让我认识了很多以前不曾认识的东西。

感谢和我一起奋斗的侯中华,李维涛,希望我们的事业能蒸蒸日上。

 

身高体重测量肥胖程度及体质健康程度

用身高和体重来测量肥胖程度与健康程度大致有两种公式

(一)身高-100/105法

     测试标准体重的公式 体重是反应和衡量一个人健康状况的重要标志之一。过胖和过瘦都不利于健康,也不会给人以健美感。不同体型的大量统计材料表明,反映正常体重较理想和简单的指标,可用身高体重的关系来表示。

    一般认为,女性的标准体重是:身高(厘米)-105=标准体重(公斤)。

    例如,一个身高160厘米的女子,她的标准体重应该是:160 (厘米)-105=55(公斤)。凡是超过标准体重10%者为偏重,超过标准体重20%以上者为肥胖,低于10%者为偏瘦,低于20%者为消瘦。

    一般认为,男性的标准体重是:身高(厘米)-100= 标准体重(公斤)。

    例如,一个身高170厘米的男子,他的标准体重应该是:170(厘米)-100=70(公斤)。凡是超过标准体重10%者为偏重,超过20%以上者为肥胖,低于10%者为偏瘦,低于20%者为消瘦。

(二)体质指数法-体重/身高的平方

    体质指数(BMI,Body Mass Index)是用于体重分类的一种全球标准,分成四个级别:正常,偏瘦,超重及肥胖。体质指数等于体重(千克)除以身高(米)的平方。直到现在,这种分类标准仍在全世界范围内用于人体体重的评估与分类。
    目前常用于判断体重超重和肥胖的简单方法是世界卫生组织(WHO)推荐的体质指数(BMI)法,计算公式为:BMI=体重(千克)除以身高(米)的平方(kg/m2)。
亚裔成年人请用以下的指引:
    体质指数            类别               罹病机会
   < 18.5                  过轻                  低
  18.5 – 22.9           正常                中等
  23 – 24.9              过重                增高
  25 – 39.9              肥胖                  高
  > 30                      痴肥                 严重
世界卫生组织对体质指数(非亚裔人士)的指引如下:
    体质指数            类别              罹病机会
    < 18.5                 过轻                  低
    18.5 – 24.9      正常                中等 
    25 – 29.9             过重                增高 
    30 – 24.9             肥胖                  高 
    35 – 39.9             痴肥                严重
    > 40                  极度痴肥        非常严重
资料来源: Asian Pacific Steering Committee in Obesity
*罹病情况包括乙型糖尿病、血糖过高症、血胰岛素过高症、高血脂症、冠心病、高血压、癌症、痛风症。

聊天机器人

前一段时间,突发奇想,开发了一个聊天机器人,本来是想做helpdesk的一个平台。support部门的人先教它,然后有问题的人可以像它请教。

教的越多它越聪明。

但是公司一直没有机器来放,只好自己搞着玩一玩。

作为公司用,只有出现解决方案才有作用。也就是当你问它比较专业的问题时,它会告诉你如何解决,解决方案1,2,3并且要出现图解的内容。所以,最好查找到相应的内容,机器人给你一个网页地址,上面包含你要查找的内容。

好了,不多说了,把开发步骤介绍一下。

(一)分析流程,需求,建立数据库。

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sogo_link]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[sogo_link](
 [id] [int] IDENTITY(1,1) NOT NULL,
 [sogo_link_url] [nvarchar](100) NULL,
 [sogo_link_font] [nvarchar](100) NULL,
 [sogo_link_login] [nvarchar](100) NULL,
 [sogo_link_alt] [nvarchar](100) NULL,
 [sogo_link_logo_or_txt] [int] NULL,
 [sogo_link_yes_no] [int] NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[robot]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[robot](
 [ID] [int] IDENTITY(1,1) NOT NULL,
 [title] [nvarchar](50) NULL,
 [robot_content] [nvarchar](4000) NULL,
 [BigClassName] [nvarchar](50) NULL,
 [SmallClassName] [nvarchar](50) NULL,
 [kin_demo] [nvarchar](4000) NULL,
 [picUrl] [nvarchar](255) NULL,
 [imagenum] [int] NULL,
 [firstImageName] [nvarchar](50) NULL,
 [robot_user] [nvarchar](50) NULL,
 [infotime] [datetime] NULL CONSTRAINT [DF_robot_infotime]  DEFAULT (getdate()),
 [hits] [int] NULL,
 [ok] [bit] NULL,
 [tuijian] [bit] NULL,
 [web_yes_no] [bit] NOT NULL,
 CONSTRAINT [PK_robot] PRIMARY KEY CLUSTERED
(
 [ID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Admin]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[Admin](
 [ID] [int] IDENTITY(1,1) NOT NULL,
 [admin] [nvarchar](50) NULL,
 [password] [nvarchar](50) NULL,
 [aleave] [nvarchar](50) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[bigClass]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[bigClass](
 [BigClassID] [int] NOT NULL,
 [BigClassName] [nvarchar](50) NULL,
 [Admin] [nvarchar](100) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[shop_pinglun]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[shop_pinglun](
 [pinglunid] [int] NOT NULL,
 [ID] [int] NULL,
 [pinglunname] [nvarchar](50) NULL,
 [pinglundate] [datetime] NULL,
 [pingluncontent] [nvarchar](max) NULL
) ON [PRIMARY]
END
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[SmallClass]’) AND type in (N’U’))
BEGIN
CREATE TABLE [dbo].[SmallClass](
 [SmallClassID] [int] NOT NULL,
 [SmallClassName] [nvarchar](50) NULL,
 [BigClassName] [nvarchar](50) NULL,
 [Admin] [nvarchar](100) NULL
) ON [PRIMARY]
END

(二)建立解决方案网页。

(三)建立web版机器人

(四)申请小I机器人,下载原程序进行修改。

using System;
using System.IO;
using System.Drawing;
using System.Configuration;
using System.Runtime.Serialization;
using System.Collections.Specialized;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.Xml.Serialization;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;
using System.Threading;

using Incesoft.BotPlatform.SDK;
using Incesoft.BotPlatform.SDK.Interface;

namespace BotPlatformConsoleServer
{
 public class MyRobot
 {
  public string address;

  public int port;

  public string user;

  public string password;

  static void Main(string[] args)
  {
   MyRobot me = new MyRobot();
   me.address = "msnbot.incesoft.com";
   me.port = 6602;
   me.user = "SP092231";
   me.password = "******";
   
   IRobotServer server = RobotServerFactory.Instance.createRobotServer(me.address, me.port);
   server.addRobotHandler(new MyHandler(server));
   server.addConnectionListener(new MyListener());
   try
   {
    server.login(me.user, me.password, 300000);
    server.requestContactList(haigangdeng@126.com);
   }
   catch (RobotException e)  
   {
    Console.Out.WriteLine("Failed to connect :" + e.Message);
   }
  }
 }

 class MyHandler : IRobotHandler
 {
  public MyHandler(IRobotServer server)
  {
   this.server = server;
  }
  private IRobotServer server;
  private Random rdm = new Random();

        public System.String commandList =  "Hi,你好,我是helpdesk小M。r" +
                                                            "如果你有************问题,可以问我。r" +
                                                            "也许我能帮你解答。";

  public System.String commandListEnt = "*****************************************r" +
                  "**  BOTPLATFORM SDK ENTERPRISE ONLY COMMAND LIST  **r" +
                  "**  Only use the following commands after upgraded your sp account  **r" +
                  "
*****************************************r" +
                  " file —— test file transfer.r" +
                  " bg ——– test background sharing.r" +
                  " ink ——- test send ink.r" +
                  " wink —— test send wink.r" +
                  " voice —– test send voiceclip.r" +
                  " webcam —- test send webcamr" +
                  " cs <account> ——– test create session.r" +
                  " pu <account> —— test push offline message.r" +
                  " iv <account> ——– test invite user.r" +
                  " ent ——— print this command list.";
 
  public virtual void  sessionOpened(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: sessionOpened");
   try
   {
    switch(session.OpenMode)
    {
     case SessionOpenMode.OPEN_MODE_CONV_OPEN:
      session.send(commandList);
      break;
     case SessionOpenMode.OPEN_MODE_ROBOT:
      session.send("You have an alert message: blablabla");
      break;
     default:
      break;
    }
   }
   catch (RobotException e)
   {
    util.consoleOut(e.ToString());
   }
  }
  
  
  public virtual void  sessionClosed(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: sessionClosed");
  }
  
  public virtual void  messageReceived(IRobotSession session, IRobotMessage message)
  {
   System.Console.Out.WriteLine("EVENT: messageReceived");
   
   try
   {
    System.String command = message.String;
    
    IRobotMessage msg = session.createMessage();

                if ("+".ToString().Equals(command[0].ToString()))
                {
                    if (command.IndexOf(‘|’) < 0)
                    {
                        session.send("问题和答案要用“|”分开吆");
                    }
                    else
                    {
                        string wenti = command.Substring(1, (command.IndexOf(‘|’) – 1));
                        string daan = command.Substring(command.IndexOf(‘|’) + 1);

                        string connectionstrings = "server=IP*****;UID=robot;PWD=******;DataBase=robot";
                        SqlConnection connection = new SqlConnection(connectionstrings);
                        string sqlxuexi = "insert into robot (title,robot_content,web_yes_no) values (" + "’" + wenti + "’," + "’" + daan + "’," + 0 + ")";
                        SqlCommand commxuexi = new SqlCommand(sqlxuexi,connection);
                        connection.Open();
                        commxuexi.ExecuteNonQuery();
                        connection.Close();

                        session.send("嗯,我记住了,谢谢你。");
                    }
                }

                else if ("help".ToUpper().Equals(command.ToUpper()) || "?".ToUpper().Equals(command.ToUpper()))
                {
                    session.send(commandList);
                }
                else if ("nudge".ToUpper().Equals(command.ToUpper()))
                {
                    session.sendNudge();
                }
    else if ("bye".ToUpper().Equals(command.ToUpper()))
    {
     session.cl
ose();
    }    
    else
                {
                    string connectionstrings = "server=IP******;UID=robot;PWD=******;DataBase=robot";
                    SqlConnection connection = new SqlConnection(connectionstrings);
                    string sqlcontent = "select * from robot where title like" + "’%" + command.ToString() + "%’";
                    SqlDataAdapter myad = new SqlDataAdapter(sqlcontent, connection);
                    connection.Open();

                    DataSet myds = new DataSet();
                    myad.Fill(myds,"robot");

                    if (myds.Tables["robot"].Rows.Count > 0)
                    {
                        int i = 0;
                        while (i < myds.Tables["robot"].Rows.Count)
                        {
                            int f = i + 1;
                            if (myds.Tables["robot"].Rows[i]["web_yes_no"].GetHashCode() == 0)
                            {
                                session.send(myds.Tables["robot"].Rows[i]["robot_content"].ToString());
                            }
                            else
                            {
                                session.send("解决方案(" + f +")n" + "http://www.xxxxx.com/robot/onews.asp?id=" + myds.Tables["robot"].Rows[i]["ID"].ToString());
                            }
                            i = i + 1;
                        }
                    }
                    else
                    {
                        session.send("对不起,我还不知道这个问题的答案,如果你知道你能告诉我吗?用“+问题|答案”的方式告诉我,我就能记住了。");
                    }
                    connection.Close();
                }
   }
   catch (RobotException e)
   {
    util.consoleOut(e.ToString());
   }   
  }
  
  public virtual void  nudgeReceived(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: nudgeReceived");
  }
  
  
  public virtual void  activityAccepted(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: activityAccepted");
  }
  
  
  public virtual void  activityRejected(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: activityRejected");
  }

  public virtual void userAdd(String robot, String user)
  {
   System.Console.Out.WriteLine("EVENT: userAdd");
  }
  
  public virtual void userRemove(String robot, String user)
  {
   System.Console.Out.WriteLine("EVENT: userRemove");
  }
  
  public virtual void  exceptionCaught(IRobotSession session, System.Exception cause)
  {
   System.Console.Out.WriteLine("SERVER ERROR: " + cause.Message);
  }

  public virtual void  activityClosed(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: activityClosed");
  }
  public virtual void  fileAccepted(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: fileAccepted");
  }
  
  public virtual void  fileRejected(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: fileRejected");
  }
  
  public virtual void  fileTransferEnded(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: fileTransferEnded");
  }
  
  public virtu
al void  backgroundAccepted(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: backgroundAccepted");
  }
  
  public virtual void  backgroundRejected(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: backgroundRejected");
  }
  
  public virtual void  backgroundTransferEnded(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: backgroundTransferEnded");
  }
  
  public virtual void  webcamAccepted(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: webcamAccepted");
  }
  
  public virtual void  webcamRejected(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: webcamRejected");
  }
    
  public virtual void  activityLoaded(IRobotSession session)
  {
   System.Console.Out.WriteLine("EVENT: activityLoaded");
  }

  public virtual void  activityReceived(IRobotSession session, System.String data)
  {
   System.Console.Out.WriteLine("EVENT: activityReceived:" + data);
  }

  public virtual void  userJoined(IRobotSession session, IRobotUser user)
  {
   System.Console.Out.WriteLine("EVENT: userJoined : " + user);
  }

  public virtual void  userLeft(IRobotSession session, IRobotUser user)
  {
   System.Console.Out.WriteLine("EVENT: userLeft :" + user);
  }
  
  public virtual void  userUpdated(IRobotUser user)
  {
   System.Console.Out.WriteLine("EVENT: userUpdated (" + user.ID +","+user.Status+","+user.FriendlyName+ ")");
  }
  
  public virtual void  personalMessageUpdated(System.String robot, System.String user, System.String personalMessage)
  {
   System.Console.Out.WriteLine("EVENT: personalMessageUpdated (" + robot + ", " + user + ", " + personalMessage + ")");
  }   
  public virtual void contactListReceived(System.String robot, System.Collections.ArrayList contactList)
  {
   System.Console.Out.WriteLine("EVENT: contactListRecieved ");
   for (int i=0; i<contactList.Count; i++)
   {
    IRobotUser user = (IRobotUser)contactList[i];
    System.Console.Out.WriteLine("User "+i+": "+user.ID);
   }
  } 
  
 }
 class MyListener : IRobotConnectionListener
 {
  public void serverConnected(IRobotServer server)
  {
   Console.Out.WriteLine("Server connected.");
  }

  public void serverReconnected(IRobotServer server)
  {
   Console.Out.WriteLine("Server reconnected.");
  }

  public void serverDisconnected(IRobotServer server)
  {
   Console.Out.WriteLine("Server disconnected.");
  }

  public void serverLoggedIn(IRobotServer sever)
  {
   Console.Out.WriteLine("Server logged in.");
  }
 }
}