亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

c#,自定義安裝,部署,創建自定義操作,自定義

系統 2059 0
最近做一個項目的安裝部署程序,要求有安裝的驗證,安裝的授權,要輸入授權嗎才可以安裝,禁止非法安裝。
一開始看見用戶界面不錯,可是添加了用戶界面不能控制他,只能接受輸入,然后根據輸入創建數據庫,修改配置之類的東西,網上的資料也多是這類型的,我就自己寫了一個,還不是不太滿意的,這些窗體都是在安裝的過程中彈出來的,我本意是想在安裝之前就驗證這些內容,可是弄不出來,不知道大家有沒有什么好的辦法。

installer1.JPG

installer2.JPG

這是需要驗證的兩個部分,兩個自定義的窗體,代碼如下:
installer類的代碼
using ?System;
using ?System.Collections.Generic;
using ?System.ComponentModel;
using ?System.Configuration.Install;
using ?System.Windows.Forms;

namespace ?FactorySetupClassLibrary
{
????[RunInstaller(
true )]
????
public ? partial ? class ?Installer1?:?Installer
????
{
????????
private ? string ?dbServer;
????????
private ? string ?loginUser;
????????
private ? string ?password;
????????
private ? string ?db;

????????
public ?Installer1()
????????
{
????????????InitializeComponent();
????????}

????????
public ? override ? void ?Install(System.Collections.IDictionary?stateSaver)
????????
{
????????????
base .Install(stateSaver);
????????????
// AuthorizeForm1?authForm?=?new?AuthorizeForm1();
????????????
// authForm.ShowDialog();
????????????DBForm1?dbForm? = ? new ?DBForm1();
????????????
if ?(dbForm.ShowDialog()? == ?DialogResult.OK)
????????????
{
????????????????
????????????}

????????????
else
????????????
{
????????????????
throw ? new ?ApplicationException( " 應用程序安裝失敗 " );
????????????}


????????????AuthorizeForm1?authForm?
= ? new ?AuthorizeForm1();
????????????
if ?(authForm.ShowDialog()? == ?DialogResult.OK)
????????????
{

????????????}

????????????
else
????????????
{
????????????????
throw ? new ?ApplicationException( " 應用程序安裝失敗 " );
????????????}

????????}

????}

}
數據庫驗證窗體的代碼

using ?System;
using ?System.Collections.Generic;
using ?System.ComponentModel;
using ?System.Data;
using ?System.Drawing;
using ?System.Text;
using ?System.Windows.Forms;
using ?System.Data.SqlClient;

namespace ?FactorySetupClassLibrary
{
????
public ? partial ? class ?DBForm1?:?Form
????
{
????????SqlConnection?conn
= null ;
????????
public ?DBForm1()
????????
{
????????????InitializeComponent();
????????}


????????
private ? void ?DBForm1_Load( object ?sender,?EventArgs?e)
????????
{
????????????txtDB.Text?
= ? " KBUdiskFactoryTools " ;
????????????txtDB.Enabled?
= ? false ;
????????????txtDBServer.Focus();
????????}


????????
private ? void ?btnOK_Click( object ?sender,?EventArgs?e)
????????
{
????????????
if ?(ValidatingHelper.ValidatingTextBox(txtDBServer,? 100 ,? " 數據庫服務器 " ,?lblDBServer)? == ? false )
????????????????
return ;
????????????
if ?(ValidatingHelper.ValidatingTextBox(txtLoginName,? 100 ,? " 登錄用戶名 " ,?lblLoginName)? == ? false )
????????????????
return ;
????????????
if ?(ValidatingHelper.ValidatingTextBox(txtPassword,? 100 ,? " 登錄密碼 " ,?lblPassword)? == ? false )
????????????????
return ;
????????????
try
????????????
{
????????????????
using ?(conn? = ? new ?SqlConnection( " server= " ? + ?txtDBServer.Text.Trim()? + ? " ;uid= " ? + ?txtLoginName.Text.Trim()? +
????????????????
" ;pwd= " ? + ?txtPassword.Text.Trim()? + ? " ;database= " ? + ?txtDB.Text.Trim()))
????????????????
{
????????????????????conn.Open();
????????????????????conn.Close();
????????????????????
this .DialogResult? = ?DialogResult.OK;
????????????????}

????????????}

????????????
catch
????????????
{
????????????????
if ?(conn.State? != ?ConnectionState.Closed)
????????????????????conn.Close();
????????????????
this .DialogResult? = ?DialogResult.Cancel;
????????????}

????????????
finally
????????????
{
????????????????
if ?(conn.State? != ?ConnectionState.Closed)
????????????????????conn.Close();
????????????}

????????}


????????
private ? void ?btnTestConnection_Click( object ?sender,?EventArgs?e)
????????
{
????????????
if ?(ValidatingHelper.ValidatingTextBox(txtDBServer,? 100 ,? " 數據庫服務器 " ,?lblDBServer)? == ? false )
????????????????
return ;
????????????
if ?(ValidatingHelper.ValidatingTextBox(txtLoginName,? 100 ,? " 登錄用戶名 " ,?lblLoginName)? == ? false )
????????????????
return ;
????????????
if ?(ValidatingHelper.ValidatingTextBox(txtPassword,? 100 ,? " 登錄密碼 " ,?lblPassword)? == ? false )
????????????????
return ;
????????????
try
????????????
{
????????????????
using ?(conn? = ? new ?SqlConnection( " server= " ? + ?txtDBServer.Text.Trim()? + ? " ;uid= " ? + ?txtLoginName.Text.Trim()? +
????????????????
" ;pwd= " ? + ?txtPassword.Text.Trim()? + ? " ;database= " ? + ?txtDB.Text.Trim()))
????????????????
{
????????????????????conn.Open();
????????????????????conn.Close();
????????????????????MessageBox.Show(
" 連接成功,可以點擊確定按鈕繼續安裝 " );
????????????????}

????????????}

????????????
catch
????????????
{
????????????????
if ?(conn.State? != ?ConnectionState.Closed)
????????????????????conn.Close();
????????????????MessageBox.Show(
" 連接失敗,請檢查連接設置之后繼續安裝 " );
????????????}

????????????
finally
????????????
{
????????????????
if ?(conn.State? != ?ConnectionState.Closed)
????????????????????conn.Close();
????????????}

????????}


????????
private ? void ?btnCancel_Click( object ?sender,?EventArgs?e)
????????
{
????????????
this .DialogResult? = ?DialogResult.Cancel;
????????}

????}

}
授權碼驗證窗體代碼

using ?System;
using ?System.Collections.Generic;
using ?System.ComponentModel;
using ?System.Data;
using ?System.Drawing;
using ?System.Text;
using ?System.Windows.Forms;


namespace ?FactorySetupClassLibrary
{
????
public ? partial ? class ?AuthorizeForm1?:?Form
????
{

????????
private ?Hasher?_hasher? = ? null ;
????????
private ? int ?_randomInt;
????????
public ?AuthorizeForm1()
????????
{
????????????InitializeComponent();

????????????_hasher?
= ? new ?Hasher();
????????}


????????
private ? void ?AuthorizeForm1_Load( object ?sender,?EventArgs?e)
????????
{
????????????Random?random?
= ? new ?Random();
????????????_randomInt?
= ?random.Next( 9999 ,? 99999 );
????????????
// this._hasher.HashText?=?this._computerInfo.GetCPUSn()?+?this._computerInfo.GetHardDriveSn()?+
????????????
// ????this._computerInfo.GetMacAddress()?+?this._computerInfo.GetMainBoardId()?+?this._randomInt.ToString();
???????????? this ._hasher.HashText? = ?ComputerInfo.GetManchineCPU()? + ?ComputerInfo.GetMachineHardDiskNumber()? +
????????????????ComputerInfo.GetMachineMac()?
+ ?ComputerInfo.GetMainBoardId()? + ? this ._randomInt.ToString();

????????????txtApplyCode.Text?
= ? this ._hasher.MD5Hasher();
????????????txtApplyCode.Enabled?
= ? false ;
????????}


????????
private ? void ?btnOK_Click( object ?sender,?EventArgs?e)
????????
{
????????????
if ?(txtAuthorizeCode.Text? == ? "" )
????????????
{
????????????????errorProvider1.SetError(lblAuthCode,?
" 請輸入授權碼 " );
????????????????txtAuthorizeCode.Focus();
????????????????
return ;
????????????}

????????????
else ? if ?(txtAuthorizeCode.TextLength? != ? 24 )
????????????
{
????????????????errorProvider1.SetError(lblAuthCode,?
" 請輸入24位的授權碼 " );
????????????????txtAuthorizeCode.SelectAll();
????????????????txtAuthorizeCode.Focus();
????????????????
return ;
????????????}

????????????
else
????????????
{
????????????????errorProvider1.SetError(lblAuthCode,?
"" );
????????????}

????????????
// this._hasher.HashText?=?txtApplyCode.Text.Trim();
????????????Hasher?hasher? = ? new ?Hasher();
????????????hasher.HashText?
= ?txtApplyCode.Text.Trim();

????????????
// MessageBox.Show("申請碼:"+txtApplyCode.Text.Trim()+"授權碼:"+hasher.MD5Hasher()+"輸入的授權碼:"+txtAuthorizeCode.Text.Trim());
???????

????????????
if ?(hasher.MD5Hasher().Equals(txtAuthorizeCode.Text.Trim()))
????????????????
this .DialogResult? = ?DialogResult.OK;
????????????
else
????????????????
this .DialogResult? = ?DialogResult.Cancel;
????????}


????????
private ? void ?btnCancel_Click( object ?sender,?EventArgs?e)
????????
{
????????????
this .DialogResult? = ?DialogResult.Cancel;
????????}

????}

}

兩個幫助類,一個是加密類,一個是輸入驗證類

using ?System;
using ?System.IO;
using ?System.Security.Cryptography;

namespace ?FactorySetupClassLibrary
{
????
/**/
????
/// ? <summary>
????
/// Copyright?(C),?2004,?kwklover(鄺偉科)
????
/// File?name:Hasher.cs
????
/// Author:鄺偉科?????Version:1.0????????Date:2004年4月22日
????
/// Description:哈希(不可逆)加密通用類庫函數
????
/// ? </summary>

???? public ? class ?Hasher
????
{
????????
private ? byte []?_HashKey;??? // 哈希密鑰存儲變量
???????? private ? string ?_HashText;?? // 待加密的字符串
???????? public ?Hasher()
????????
{
????????????
//
????????????
// ?TODO:?在此處添加構造函數邏輯
????????????
//
????????}

????????
/// ? <summary>
????????
/// ?帶參數構造函數
????????
/// ? </summary>
????????
/// ? <param?name="hashText"> 待加密的字符串 </param>

???????? public ?Hasher( string ?hashText)
????????
{
????????????
this ._HashText? = ?hashText;
????????}

????????
/**/
????????
/// ? <summary>
????????
/// ?哈希密鑰
????????
/// ? </summary>

???????? public ? byte []?HashKey
????????
{
????????????
set
????????????
{
????????????????_HashKey?
= ?value;
????????????}

????????????
get
????????????
{
????????????????
return ?_HashKey;
????????????}

????????}


????????
/**/
????????
/// ? <summary>
????????
/// ?需要產生加密哈希的字符串
????????
/// ? </summary>

???????? public ? string ?HashText
????????
{
????????????
set
????????????
{
????????????????_HashText?
= ?value;
????????????}

????????????
get
????????????
{
????????????????
return ?_HashText;
????????????}

????????}


????????
/**/
????????
/// ? <summary>
????????
/// ?使用HMACSHA1類產生長度為?20?字節的哈希序列。需提供相應的密鑰,接受任何大小的密鑰。
????????
/// ? </summary>
????????
/// ? <returns></returns>

???????? public ? string ?HMACSHA1Hasher()
????????
{
????????????
byte []?HmacKey? = ?HashKey;
????????????
byte []?HmacData? = ?System.Text.Encoding.UTF8.GetBytes(HashText);

????????????HMACSHA1?Hmac?
= ? new ?HMACSHA1(HmacKey);

????????????CryptoStream?cs?
= ? new ?CryptoStream(Stream.Null,?Hmac,?CryptoStreamMode.Write);
????????????cs.Write(HmacData,?
0 ,?HmacData.Length);
????????????cs.Close();

????????????
byte []?Result? = ?Hmac.Hash;

????????????
return ?Convert.ToBase64String(Result);?? // 返回長度為28字節字符串
????????}


????????
/**/
????????
/// ? <summary>
????????
/// ?使用MACTripleDES類產生長度為?8?字節的哈希序列。需提供相應的密鑰,密鑰長度可為?8、16?或?24?字節的密鑰。
????????
/// ? </summary>
????????
/// ? <returns></returns>

???????? public ? string ?MACTripleDESHasher()
????????
{
????????????
byte []?MacKey? = ?HashKey;
????????????
byte []?MacData? = ?System.Text.Encoding.UTF8.GetBytes(HashText);

????????????MACTripleDES?Mac?
= ? new ?MACTripleDES(MacKey);

????????????
byte []?Result? = ?Mac.ComputeHash(MacData);

????????????
return ?Convert.ToBase64String(Result);?? // 返回長度為12字節字符串
????????}


????????
/**/
????????
/// ? <summary>
????????
/// ?使用MD5CryptoServiceProvider類產生哈希值。不需要提供密鑰。
????????
/// ? </summary>
????????
/// ? <returns></returns>

???????? public ? string ?MD5Hasher()
????????
{
????????????
byte []?MD5Data? = ?System.Text.Encoding.UTF8.GetBytes(HashText);

????????????MD5?Md5?
= ? new ?MD5CryptoServiceProvider();

????????????
byte []?Result? = ?Md5.ComputeHash(MD5Data);

????????????
return ?Convert.ToBase64String(Result);? // 返回長度為25字節字符串
????????}


????????
/**/
????????
/// ? <summary>
????????
/// ?使用SHA1Managed類產生長度為160位哈希值。不需要提供密鑰。
????????
/// ? </summary>
????????
/// ? <returns></returns>

???????? public ? string ?SHA1ManagedHasher()
????????
{
????????????
byte []?SHA1Data? = ?System.Text.Encoding.UTF8.GetBytes(HashText);

????????????SHA1Managed?Sha1?
= ? new ?SHA1Managed();

????????????
byte []?Result? = ?Sha1.ComputeHash(SHA1Data);

????????????
return ?Convert.ToBase64String(Result);? // 返回長度為28字節的字符串
????????}


????????
/**/
????????
/// ? <summary>
????????
/// ?使用SHA256Managed類產生長度為256位哈希值。不需要提供密鑰。
????????
/// ? </summary>
????????
/// ? <returns></returns>

???????? public ? string ?SHA256ManagedHasher()
????????
{
????????????
byte []?SHA256Data? = ?System.Text.Encoding.UTF8.GetBytes(HashText);

????????????SHA256Managed?Sha256?
= ? new ?SHA256Managed();

????????????
byte []?Result? = ?Sha256.ComputeHash(SHA256Data);

????????????
return ?Convert.ToBase64String(Result);?? // 返回長度為44字節的字符串
????????}


????????
/**/
????????
/// ? <summary>
????????
/// ?使用SHA384Managed類產生長度為384位哈希值。不需要提供密鑰。
????????
/// ? </summary>
????????
/// ? <returns></returns>

???????? public ? string ?SHA384ManagedHasher()
????????
{
????????????
byte []?SHA384Data? = ?System.Text.Encoding.UTF8.GetBytes(HashText);

????????????SHA384Managed?Sha384?
= ? new ?SHA384Managed();

????????????
byte []?Result? = ?Sha384.ComputeHash(SHA384Data);

????????????
return ?Convert.ToBase64String(Result);?? // 返回長度為64字節的字符串
????????}


????????
/**/
????????
/// ? <summary>
????????
/// ?使用SHA512Managed類產生長度為512位哈希值。不需要提供密鑰。
????????
/// ? </summary>
????????
/// ? <returns></returns>

???????? public ? string ?SHA512ManagedHasher()
????????
{
????????????
byte []?SHA512Data? = ?System.Text.Encoding.UTF8.GetBytes(HashText);

????????????SHA512Managed?Sha512?
= ? new ?SHA512Managed();

????????????
byte []?Result? = ?Sha512.ComputeHash(SHA512Data);

????????????
return ?Convert.ToBase64String(Result);?? // 返回長度為88字節的字符串
????????}

????}

}




文本框輸入內容驗證類

using ?System;
using ?System.Collections.Generic;
using ?System.Text;
using ?System.Windows.Forms;

namespace ?FactorySetupClassLibrary
{
????
/// ? <summary>
????
/// ?輸入驗證幫助類
????
/// ? </summary>

??? public ?? class ?ValidatingHelper
????
{
???????
/// ? <summary>
???????
/// ?驗證輸入文本框控件
???????
/// ? </summary>
???????
/// ? <param?name="validatedControl"> 需要驗證的控件 </param>
???????
/// ? <param?name="length"> 輸入長度 </param>
???????
/// ? <param?name="msg"> 文本框的驗證內容 </param>
???????
/// ? <param?name="msgControl"> 顯示錯誤信息的控件 </param>
???????
/// ? <returns></returns>

??????? public ? static ? bool ?ValidatingTextBox(Control?validatedControl, int ?length,? string ?msg,?Control?msgControl)
???????
{
???????????ErrorProvider?error?
= ? new ?ErrorProvider();
???????????
if ?(validatedControl.Text? == ? "" )
???????????
{
???????????????error.SetError(msgControl,?
" 請輸入 " ? + ?msg);
???????????????validatedControl.Focus();
???????????????
return ? false ;
???????????}

???????????
else ?
???????????
{
???????????????error.SetError(msgControl,?
"" );
???????????????
return ? true ;
???????????}


???????}

????}

}






c#,自定義安裝,部署,創建自定義操作,自定義操作,安裝驗證,數據庫,安裝授權碼,接收輸入,判斷


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 操美女的视频网站 | 亚洲黄色自拍 | 一区二区三区精品国产 | 亚洲美女亚洲精品久久久久 | 亚洲欧美专区精品久久 | 免费观看日本高清a毛片 | 久久96国产精品久久久 | 日本精a在线观看 | 91福利合集 | 国产一区免费视频 | 亚洲精品免费在线视频 | 99久久精品国产一区二区三区 | 一级毛片一级毛片一级级毛片 | 日本不卡毛片一二三四 | 亚洲国产中文字幕 | 亚洲国产精品第一区二区三区 | 337p亚洲精品色噜噜狠狠 | 色中文字幕在线 | 成人日b视频 | 日本a毛片在线播放 | 牛牛影视午夜免费福利 | 99精品视频免费 | 亚洲va天堂va欧美ⅴa | 中文字幕中文字幕在线 | 国产视频在线观看福利 | 四虎在线视频免费观看 | 天天爱天天爽 | 天天碰夜夜操 | 欧美色成人tv在线播放 | 精品久久久99大香线蕉 | 日本爱爱网站 | 久久精品国产一区二区三区不卡 | 在线不卡视频 | 国内精品久久久久影院不卡 | 国产在线视精品麻豆 | julia中文字幕在线 | 韩国成人毛片aaa黄 韩国高清不卡一区二区 | 国产精品欧美日韩一区二区 | 国产福利影院在线观看 | 欧美一级免费大片 | 天天干天天干天天操 |