Application Development

Software technique, Skills & Applications

Dataview March 22, 2008

Filed under: .Net C# VB.Net — meetme @ 1:34 pm

 protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add(“onmouseover”, “c=this.style.backgroundColor;this.style.backgroundColor=’#00ffee’;”);
            e.Row.Attributes.Add(“onmouseout”, “this.style.backgroundColor=c”);
        }
    }
    protected void GridView1_DataBound(object sender, EventArgs e)
    {
      
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        for (int i = 0; i < GridView1.Rows.Count; i++)
        {
            string lbl = Convert.ToString(DataBinder.Eval(e.Row.DataItem,”CategoryName”));
            if (lbl == “Produce”)
            {
                e.Row.BackColor = System.Drawing.Color.Beige;
            }
        }
    }

 

全文检索 March 12, 2008

Filed under: .Net C# VB.Net — meetme @ 4:02 pm

Lucnene.Net

 

March 12, 2008

Filed under: .Net C# VB.Net — meetme @ 2:08 am
public static class ScottGuExtensions
{
    
public static bool IsValidEmailAddress(this string s)
    {
        Regex regex 
= new Regex(@”^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$”);
        return 
regex.IsMatch(s);
    
}
}
 

序列化问题 March 8, 2008

Filed under: .Net C# VB.Net — meetme @ 10:58 pm

序列化问题

[Serializable]
 public   class   FatherClass {
        private   string   id;
        public   string   Id
        {
                get   {   return   id;}
                set   {   id   =   value;   }
        }
}
子类
[Serializable]
public   class   ChildClass   :   FatherClass
{
 
       private   string   childname;
        public   string   Childname
        {
                get   {   return   childname;   }
                set   {   childname   =   value;   }
        }
}

WebService定义
[XmlInclude(typeof(FatherClass))]
[XmlInclude(typeof(ChildClass))]
[WebMethod]
public   FatherClassHelloStus(FatherClass   obj)
{
        ChildClass   child   =   (ChildClass)obj;
        ….         return   child;
}

 

.net获取系统特殊文件夹路径(收藏夹,桌面) March 2, 2008

Filed under: .Net C# VB.Net — meetme @ 12:00 pm
1. 收藏夹路径
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Favorites)
2. 桌面路径
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Desktop)

更多请见枚举类
System.Environment.SpecialFolder

 

decimal to hex and hex to decimal February 3, 2008

Filed under: .Net C# VB.Net — meetme @ 2:14 pm
// Store integer 182
int decValue = 182;
// Convert integer 182 as a hex in a string variable
string hexValue = decValue.ToString(“X”);
// Convert the hex string back to the number
int decAgain = int.Parse(hexValue, System.Globalization.NumberStyles.HexNumber);
 

文件信息 February 1, 2008

Filed under: .Net C# VB.Net — meetme @ 2:13 am

FileInfo

 

通过.Net FrameWork 2.0下提供的“System.Net.Mail”可以轻松的实现 January 5, 2008

Filed under: .Net C# VB.Net — meetme @ 2:28 pm

 通过.Net FrameWork 2.0下提供的“System.Net.Mail”可以轻松的实现,本文列举了3种途径来发送:
1.通过Localhost;
2.通过普通SMTP;
3.通过SSL的SMTP;

下面一个一个来说:

1.通过LocalHost
1public void SendMailLocalhost()
2 {
3 System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
4 msg.To.Add(a@a.com);
5 msg.To.Add(b@b.com);
6 /**//*
7 * msg.To.Add(“b@b.com”);
8 * msg.To.Add(“b@b.com”);
9 * msg.To.Add(“b@b.com”);可以发送给多人
10 */

11 msg.CC.Add(c@c.com);
12 /**//*
13 * msg.CC.Add(“c@c.com”);
14 * msg.CC.Add(“c@c.com”);可以抄送给多人
15 */

16 msg.From = new MailAddress(a@a.com, AlphaWu, System.Text.Encoding.UTF8);
17 /**//* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
18 msg.Subject = 这是测试邮件;//邮件标题
19 msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
20 msg.Body = 邮件内容;//邮件内容
21 msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
22 msg.IsBodyHtml = false;//是否是HTML邮件
23 msg.Priority = MailPriority.High;//邮件优先级
24
25 SmtpClient client = new SmtpClient();
26 client.Host = localhost;
27 object userState = msg;
28 try
29 {
30 client.SendAsync(msg, userState);
31 //简单一点儿可以client.Send(msg);
32 MessageBox.Show(发送成功);
33 }

34 catch (System.Net.Mail.SmtpException ex)
35 {
36 MessageBox.Show(ex.Message, 发送邮件出错);
37 }

38 }

39
2.通过普通SMTP
1public void SendMailUseZj()
2 {
3 System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
4 msg.To.Add(a@a.com);
5 msg.To.Add(b@b.com);
6 /**//*
7 * msg.To.Add(“b@b.com”);
8 * msg.To.Add(“b@b.com”);
9 * msg.To.Add(“b@b.com”);可以发送给多人
10 */

11 msg.CC.Add(c@c.com);
12 /**//*
13 * msg.CC.Add(“c@c.com”);
14 * msg.CC.Add(“c@c.com”);可以抄送给多人
15 */

16 msg.From = new MailAddress(a@a.com, AlphaWu, System.Text.Encoding.UTF8);
17 /**//* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
18 msg.Subject = 这是测试邮件;//邮件标题
19 msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
20 msg.Body = 邮件内容;//邮件内容
21 msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
22 msg.IsBodyHtml = false;//是否是HTML邮件
23 msg.Priority = MailPriority.High;//邮件优先级
24
25 SmtpClient client = new SmtpClient();
26 client.Credentials = new System.Net.NetworkCredential(username@zj.com, userpass);
27 //在zj.com注册的邮箱和密码
28 client.Host = smtp.zj.com;
29 object userState = msg;
30 try
31 {
32 client.SendAsync(msg, userState);
33 //简单一点儿可以client.Send(msg);
34 MessageBox.Show(发送成功);
35 }

36 catch (System.Net.Mail.SmtpException ex)
37 {
38 MessageBox.Show(ex.Message, 发送邮件出错);
39 }

40 }

3.通过SSL的SMTP
1public void SendMailUseGmail()
2 {
3 System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
4 msg.To.Add(a@a.com);
5 msg.To.Add(b@b.com);
6 /**//*
7 * msg.To.Add(“b@b.com”);
8 * msg.To.Add(“b@b.com”);
9 * msg.To.Add(“b@b.com”);可以发送给多人
10 */

11 msg.CC.Add(c@c.com);
12 /**//*
13 * msg.CC.Add(“c@c.com”);
14 * msg.CC.Add(“c@c.com”);可以抄送给多人
15 */

16 msg.From = new MailAddress(a@a.com, AlphaWu, System.Text.Encoding.UTF8);
17 /**//* 上面3个参数分别是发件人地址(可以随便写),发件人姓名,编码*/
18 msg.Subject = 这是测试邮件;//邮件标题
19 msg.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码
20 msg.Body = 邮件内容;//邮件内容
21 msg.BodyEncoding = System.Text.Encoding.UTF8;//邮件内容编码
22 msg.IsBodyHtml = false;//是否是HTML邮件
23 msg.Priority = MailPriority.High;//邮件优先级
24
25 SmtpClient client = new SmtpClient();
26 client.Credentials = new System.Net.NetworkCredential(username@gmail.com, password);
27 //上述写你的GMail邮箱和密码
28 client.Port = 587;//Gmail使用的端口
29 client.Host = smtp.gmail.com;
30 client.EnableSsl = true;//经过ssl加密
31 object userState = msg;
32 try
33 {
34 client.SendAsync(msg, userState);
35 //简单一点儿可以client.Send(msg);
36 MessageBox.Show(发送成功);
37 }

38 catch (System.Net.Mail.SmtpException ex)
39 {
40 MessageBox.Show(ex.Message, 发送邮件出错);
41 }

42 }

43

通过Gmail来发送邮件,成功率极高,几乎都可以发到,推荐使用。

 

DataGridView中如何在输入数据后将焦点定位到指定的单元格? December 23, 2007

Filed under: .Net C# VB.Net — meetme @ 6:45 am

方法如下: Protected Overrides Function ProcessCmdKey(ByRef aoMsg As Message, ByVal aoKey As Keys) As Boolean If Me.ActiveControl.GetType.Name.Equals(“DataGridViewTextBoxEditingControl”) Then If aoKey = Keys.Enter Then Dim EditControl As DataGridViewTextBoxEditingControl = Me.ActiveControl Dim dg As DataGridView = EditControl.EditingControlDataGridView dg.EndEdit() ‘自己控制单元格的位置 dg.CurrentCell = dg.Item(4, 8) End If Else MyBase.ProcessCmdKey(aoMsg, aoKey) End If End Function

 

用C#怎么做电话拨号程序 November 24, 2007

Filed under: .Net C# VB.Net — meetme @ 1:26 am

http://topic.csdn.net/t/20060104/22/4498631.html

Public   Class   Form1  
          Inherits   System.Windows.Forms.Form  
   
  #Region   ”   Windows   窗体设计器生成的代码   ”  
   
          Public   Sub   New()  
                  MyBase.New()  
   
                  ‘该调用是   Windows   窗体设计器所必需的。  
                  InitializeComponent()  
   
                  ‘在   InitializeComponent()   调用之后添加任何初始化  
   
          End   Sub  
   
          ‘窗体重写   dispose   以清理组件列表。  
          Protected   Overloads   Overrides   Sub   Dispose(ByVal   disposing   As   Boolean)  
                  If   disposing   Then  
                          If   Not   (components   Is   Nothing)   Then  
                                  components.Dispose()  
                          End   If  
                  End   If  
                  MyBase.Dispose(disposing)  
          End   Sub  
   
          ‘Windows   窗体设计器所必需的  
          Private   components   As   System.ComponentModel.IContainer  
   
          ‘注意:   以下过程是   Windows   窗体设计器所必需的  
          ‘可以使用   Windows   窗体设计器修改此过程。  
          ‘不要使用代码编辑器修改它。  
          Friend   WithEvents   Label1   As   System.Windows.Forms.Label  
          Friend   WithEvents   TextBox1   As   System.Windows.Forms.TextBox  
          Friend   WithEvents   Button1   As   System.Windows.Forms.Button  
          Friend   WithEvents   Button2   As   System.Windows.Forms.Button  
          Friend   WithEvents   ListBox1   As   System.Windows.Forms.ListBox  
          Friend   WithEvents   Icon1   As   System.Windows.Forms.NotifyIcon  
          Friend   WithEvents   ContextMenu1   As   System.Windows.Forms.ContextMenu  
          Friend   WithEvents   MenuItem1   As   System.Windows.Forms.MenuItem  
          Friend   WithEvents   MenuItem2   As   System.Windows.Forms.MenuItem  
          <System.Diagnostics.DebuggerStepThrough()>   Private   Sub   InitializeComponent()  
                  Me.components   =   New   System.ComponentModel.Container  
                  Dim   resources   As   System.Resources.ResourceManager   =   New   System.Resources.ResourceManager(GetType(Form1))  
                  Me.Label1   =   New   System.Windows.Forms.Label  
                  Me.TextBox1   =   New   System.Windows.Forms.TextBox  
                  Me.Button1   =   New   System.Windows.Forms.Button  
                  Me.Button2   =   New   System.Windows.Forms.Button  
                  Me.ListBox1   =   New   System.Windows.Forms.ListBox  
                  Me.Icon1   =   New   System.Windows.Forms.NotifyIcon(Me.components)  
                  Me.ContextMenu1   =   New   System.Windows.Forms.ContextMenu  
                  Me.MenuItem1   =   New   System.Windows.Forms.MenuItem  
                  Me.MenuItem2   =   New   System.Windows.Forms.MenuItem  
                  Me.SuspendLayout()  
                  ‘  
                  ‘Label1  
                  ‘  
                  Me.Label1.Location   =   New   System.Drawing.Point(8,   8)  
                  Me.Label1.Name   =   “Label1″  
                  Me.Label1.Size   =   New   System.Drawing.Size(160,   16)  
                  Me.Label1.TabIndex   =   0  
                  Me.Label1.Text   =   “请输入你要拨的电话号码:”  
                  ‘  
                  ‘TextBox1  
                  ‘  
                  Me.TextBox1.Location   =   New   System.Drawing.Point(8,   24)  
                  Me.TextBox1.Name   =   “TextBox1″  
                  Me.TextBox1.Size   =   New   System.Drawing.Size(272,   21)  
                  Me.TextBox1.TabIndex   =   1  
                  Me.TextBox1.Text   =   “”  
                  ‘  
                  ‘Button1  
                  ‘  
                  Me.Button1.Location   =   New   System.Drawing.Point(24,   56)  
                  Me.Button1.Name   =   “Button1″  
                  Me.Button1.TabIndex   =   2  
                  Me.Button1.Text   =   “拨号”  
                  ‘  
                  ‘Button2  
                  ‘  
                  Me.Button2.Location   =   New   System.Drawing.Point(192,   56)  
                  Me.Button2.Name   =   “Button2″  
                  Me.Button2.TabIndex   =   3  
                  Me.Button2.Text   =   “退出”  
                  ‘  
                  ‘ListBox1  
                  ‘  
                  Me.ListBox1.ItemHeight   =   12  
                  Me.ListBox1.Location   =   New   System.Drawing.Point(8,   88)  
                  Me.ListBox1.Name   =   “ListBox1″  
                  Me.ListBox1.Size   =   New   System.Drawing.Size(272,   76)  
                  Me.ListBox1.TabIndex   =   4  
                  ‘  
                  ‘Icon1  
                  ‘  
                  Me.Icon1.ContextMenu   =   Me.ContextMenu1  
                  Me.Icon1.Icon   =   CType(resources.GetObject(“Icon1.Icon”),   System.Drawing.Icon)  
                  Me.Icon1.Text   =   “电话拨号”  
                  Me.Icon1.Visible   =   True  
                  ‘  
                  ‘ContextMenu1  
                  ‘  
                  Me.ContextMenu1.MenuItems.AddRange(New   System.Windows.Forms.MenuItem()   {Me.MenuItem1,   Me.MenuItem2})  
                  ‘  
                  ‘MenuItem1  
                  ‘  
                  Me.MenuItem1.Index   =   0  
                  Me.MenuItem1.Text   =   “退出”  
                  ‘  
                  ‘MenuItem2  
                  ‘  
                  Me.MenuItem2.Index   =   1  
                  Me.MenuItem2.Text   =   “还原”  
                  ‘  
                  ‘Form1  
                  ‘  
                  Me.AutoScaleBaseSize   =   New   System.Drawing.Size(6,   14)  
                  Me.ClientSize   =   New   System.Drawing.Size(292,   174)  
                  Me.Controls.Add(Me.ListBox1)  
                  Me.Controls.Add(Me.Button2)  
                  Me.Controls.Add(Me.Button1)  
                  Me.Controls.Add(Me.TextBox1)  
                  Me.Controls.Add(Me.Label1)  
                  Me.Icon   =   CType(resources.GetObject(“$this.Icon”),   System.Drawing.Icon)  
                  Me.Name   =   “Form1″  
                  Me.Text   =   “电话拨号”  
                  Me.ResumeLayout(False)  
   
          End   Sub  
   
  #End   Region  
   
          Private   Declare   Function   tapiRequestMakeCall   Lib   “tapi32.dll”   (ByVal   DestAddress   As   String,   ByVal   AppName   As   String,   ByVal   CalledParty   As   String,   ByVal   comment   As   String)   As   Integer  
          Const   TAPIERR_CONNECTED   As   Short   =   0  
          Const   TAPIERR_DROPPED   As   Short   =   -1  
          Const   TAPIERR_NOREQUESTRECIPIENT   As   Short   =   -2  
          Const   TAPIERR_REQUESTQUEUEFULL   As   Short   =   -3  
          Const   TAPIERR_INVALDESTADDRESS   As   Short   =   -4  
          Const   TAPIERR_DESTBUSY   As   Short   =   -11  
          Const   TAPIERR_UNKNOWNREQUESTID   As   Short   =   -15  
          Const   TAPIERR_REQUESTFAILED   As   Short   =   -16  
   
          Private   Sub   EnableDial()  
                  Button1.Enabled   =   Len(Trim(TextBox1.Text))   >   0  
          End   Sub  
   
          Sub   tapiStatus(ByRef   strres   As   Integer)  
                  Select   Case   strres  
                          Case   TAPIERR_CONNECTED  
                                  ListBox1.Items.Add(“信息:拨号已连接!”)  
                          Case   TAPIERR_INVALDESTADDRESS  
                                  ListBox1.Items.Add(“错误:错误的目的地址!”)  
                          Case   TAPIERR_NOREQUESTRECIPIENT  
                                  ListBox1.Items.Add(“错误:没有电话接口程序运行!”)  
                          Case   TAPIERR_REQUESTFAILED  
                                  ListBox1.Items.Add(“错误:拨号请求由于未知原因失败!”)  
                          Case   TAPIERR_DESTBUSY  
                                  ListBox1.Items.Add(“错误:对方电话正忙!”)  
                          Case   TAPIERR_UNKNOWNREQUESTID  
                                  ListBox1.Items.Add(“错误:没有这个电话号码!”)  
                          Case   TAPIERR_DROPPED  
                                  ListBox1.Items.Add(“错误:对方已挂断!”)  
                  End   Select  
          End   Sub  
          Private   Sub   Button1_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button1.Click  
                  Dim   strPhoneNum   As   String  
                  Dim   res   As   Integer  
                  If   Trim(TextBox1.Text)   =   “”   Then  
                          ListBox1.Items.Add(“错误:没有输入电话号码!”)  
                          Exit   Sub  
                  Else  
                          strPhoneNum   =   TextBox1.Text  
                  End   If  
   
                  res   =   tapiRequestMakeCall(strPhoneNum,   “Tapi   Sample”,   strPhoneNum,   “”)  
                  Call   tapiStatus(res)  
          End   Sub  
   
          Private   Sub   Button2_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   Button2.Click  
                  Close()  
          End   Sub  
   
          Private   Sub   Form1_MinimumSizeChanged(ByVal   sender   As   Object,   ByVal   e   As   System.EventArgs)   Handles   MyBase.MinimumSizeChanged  
                  Icon1.Visible   =   True  
          End   Sub  
   
          Private   Sub   MenuItem1_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   MenuItem1.Click  
                  Close()  
          End   Sub  
   
          Private   Sub   MenuItem2_Click(ByVal   sender   As   System.Object,   ByVal   e   As   System.EventArgs)   Handles   MenuItem2.Click  
                  Me.Show()  
          End   Sub  
  End   Class