实现的功能是客户打开登录界面,输入账户密码,加载revit插件并打开revit
创建Command建
public class LoginCommand : ICommand
{
readonly Func<Boolean> _canExecute;
readonly Action _execute;
public LoginCommand(Action execute) : this(execute, null) { }
public LoginCommand(Action execute, Func<Boolean> canExecute)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
}
public event EventHandler CanExecuteChanged
{
add
{
if (_canExecute != null)
CommandManager.RequerySuggested += value;
}
remove
{
if (_canExecute != null)
CommandManager.RequerySuggested -= value;
}
}
[DebuggerStepThrough]
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute();
}
public void Execute(object parameter)
{
_execute();
}
}
创建ViewModel
public class LoginViewModel: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
public LoginViewModel()
{
}
private string username;
public string UserName
{
get { return username; }
set { username = value;RaisePropertyChanged("UserName"); }
}
private string userpass;
public string UserPass
{
get { return userpass; }
set { userpass = value; RaisePropertyChanged("UserPass"); }
}
private string tipaccount;
public string Tipaccount
{
get { return tipaccount; }
set { tipaccount = value; RaisePropertyChanged("Tipaccount"); }
}
void UpdateNameExecute()
{
if (this.UserName =="Admin" && this.UserPass=="123456")
{
MessageBox.Show("登录成功");
string Name = GetIntallPathInfo("2019");
Process pro = System.Diagnostics.Process.Start(Name);
// SetCache.SetCacheing();
//Add();
}
//this.UserName = "黄昏前黎明后";
//this.UserPass = "中软易通科技";
}
public static void Add()
{
try
{
Console.WriteLine("正在查找已经注册的程序.....");
RegistryKey key = Registry.ClassesRoot;
key.DeleteSubKeyTree(@"gitwms");
Console.WriteLine("已经清除注册程序.....");
}
catch (Exception e)
{
Console.WriteLine("未找到注册的程序...");
}
/*===============================================*/
Console.WriteLine("开始注册程序....");
RegistryKey regWrite = Registry.ClassesRoot.CreateSubKey("gitwms");
regWrite.SetValue("", "URL:自定义协议");
regWrite.SetValue("URL Protocol", "URL Protocol");
regWrite.Close();
regWrite = Registry.ClassesRoot.CreateSubKey(@"gitwms\shell");
regWrite.Close();
regWrite = Registry.ClassesRoot.CreateSubKey(@"gitwms\shell\open");
regWrite.Close();
regWrite = Registry.ClassesRoot.OpenSubKey(@"gitwms\shell\open", true);
RegistryKey aimdir = regWrite.CreateSubKey("command");
string BaseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string AppPath = Path.Combine(BaseDirectory, "D:\\Revit2019_SetUp\\Revit 2019\\Revit.exe");
aimdir.SetValue(@"", "\"" + AppPath + "\" \" %1\"");
regWrite.Close();
aimdir.Close();
}
/// <summary>
///
/// </summary>
/// <param name="Version"></param>
/// <returns></returns>
public static string GetIntallPathInfo(string Version)
{
try
{
string ExeName = "Revit.exe";
string SubKeyName = string.Format(@"SOFTWARE\Autodesk\Revit\{0}\REVIT-05:0804", Version);
//RegistryKey regKey = Registry.LocalMachine;
//RegistryKey regSubKey = regKey.OpenSubKey("SOFTWARE\\Autodesk\\Revit\\", false);
//Registry.LocalMachine
using (RegistryKey RegistryKey1 = Registry.LocalMachine.OpenSubKey(SubKeyName, false))
{
if (RegistryKey1 == null)
{
return string.Empty;
}
if (RegistryKey1.GetSubKeyNames() == null)
{
return string.Empty;
}
//RegistryKey RegistryKey2 = RegistryKey1.OpenSubKey(SoftName, false);
//RegistryKey RegistryKey2 = RegistryKey1.OpenSubKey(SubKeyName, false);
//if (RegistryKey2 == null)
//{
// return string.Empty;
//}
//获取软件名
string SoftwareName = RegistryKey1.GetValue("ProductName", "").ToString();
//安装地址信息
string InstallLocation = RegistryKey1.GetValue("InstallationLocation", "").ToString();
return System.IO.Path.Combine(InstallLocation, ExeName);
}
}
catch (Exception)
{
return string.Empty;
}
}
bool CanUpdateNameExecute()
{
return true;
}
void UpdatatipaccountExecute()
{
if (this.UserName == null)
{
this.Tipaccount = "请输入邮箱或者手机号";
}
else
{
this.Tipaccount = "";
}
}
bool CanUpdatatipaccountExecute()
{
return true;
}
public ICommand UpdateName
{
get { return new LoginCommand(UpdateNameExecute, CanUpdateNameExecute); }
}
public ICommand Updatatipaccount
{
get { return new LoginCommand(UpdatatipaccountExecute, CanUpdatatipaccountExecute); }
}
}
源码下载地址链接:https://pan.baidu.com/s/1_XgkLvixIvDZYURJP_TmEQ
提取码:m8sk
复制这段内容后打开百度网盘手机App,操作更方便哦--来自百度网盘超级会员V1的分享