无法从双精度转换为字符串c#
我已经试过了,但它给了我一个错误“无法从double转换为string”,我想将变量无法从双精度转换为字符串c#,c#,C#,我已经试过了,但它给了我一个错误“无法从double转换为string”,我想将变量ProgressBarMegabyte更改为下面的等式 ProgressBarMegabyte = (Int32.Parse(ProgressBarMegabyte) + Double.Parse(Convert.ToString(ProgressedMegabytes))); 我的全部代码: using System; using System.Collections.Generic; using Syste
ProgressBarMegabyte
更改为下面的等式
ProgressBarMegabyte = (Int32.Parse(ProgressBarMegabyte) + Double.Parse(Convert.ToString(ProgressedMegabytes)));
我的全部代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace SoftwareStoreClientDownloader
{
public partial class OfflineInstaller : Form
{
public OfflineInstaller()
{
InitializeComponent();
FormClosing += OfflineInstaller_FormClosing;
}
private void OfflineInstaller_FormClosing(object sender, FormClosingEventArgs e)
{
File.WriteAllText("C:\\Closed.txt", "true");
}
private void OfflineInstaller_Load(object sender, EventArgs e)
{
if (!Directory.Exists("C:\\Program Files\\SoftwareStoreOffline"))
{
Directory.CreateDirectory("C:\\Program Files\\SoftwareStoreOffline");
}
}
private void BrowseButton_Click(object sender, EventArgs e)
{
SaveFileDialog s = new SaveFileDialog();
s.DefaultExt = "iso";
s.AddExtension = false;
s.CheckPathExists = true;
s.ShowDialog();
try
{
BrowseFileTextBox.Text = s.FileName;
}
catch (Exception dew)
{
}
}
private async void button1_Click(object sender, EventArgs e)
{
var i = 2;
button1.Enabled = false;
button1.Text = "Initializing";
await Initialize();
button1.Text = "Downloading";
TotalProgressBar.Maximum = Int32.Parse(Parts);
if (Int32.Parse(Parts) > 99)
{
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline" + Database +
"/master/SoftwareStore" + Version + "Setup-Files.part001.exe",
MainDirectory + "\\" + "Setup-Files.part001.exe");
}
else
{
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline" + Database +
"/master/SoftwareStore" + Version + "Setup-Files.part01.exe",
MainDirectory + "\\" + "Setup-Files.part01.exe");
}
var TotalProgressBytes = ((Int32.Parse(TotalBytes) / 1024d / 1024d) * Int32.Parse(Parts));
var TotalMegabytes = TotalProgressBytes;
var ProgressedMegabytes = (Int32.Parse(TotalBytes) / 1024d / 1024d);
var ProgressBarMegabyte = string.Empty;
ProgressBarMegabyte = ProgressedMegabytes.ToString();
while (i < Int32.Parse(Parts) + 1)
{
if (Int32.Parse(Parts) < 100)
{
if (i < 10)
{
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline" + Database +
"/master/SoftwareStore" + Version + "Setup-Files.part0" + i + ".rar",
MainDirectory + "\\" + "Setup-Files.part0" + i + ".rar");
}
else
{
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline" + Database +
"/master/SoftwareStore" + Version + "Setup-Files.part" + i + ".rar",
MainDirectory + "\\" + "Setup-Files.part" + i + ".rar");
}
}
else if (Int32.Parse(Parts) > 99)
{
if (i < 10 && i < 100)
{
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline" + Database +
"/master/SoftwareStore" + Version + "Setup-Files.part00" + i + ".rar",
MainDirectory + "\\" + "Setup-Files.part00" + i + ".rar");
}
else if(i > 10 && i < 100)
{
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline" + Database +
"/master/SoftwareStore" + Version + "Setup-Files.part0" + i + ".rar",
MainDirectory + "\\" + "Setup-Files.part0" + i + ".rar");
}
else if (i > 99)
{
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline" + Database +
"/master/SoftwareStore" + Version + "Setup-Files.part" + i + ".rar",
MainDirectory + "\\" + "Setup-Files.part" + i + ".rar");
}
}
else if (Int32.Parse(Parts) < 10)
{
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline" + Database +
"/master/SoftwareStore" + Version + "Setup-Files.part" + i + ".rar",
MainDirectory + "\\" + "Setup-Files.part" + i + ".rar");
}
DownloadProgressLabel.Text = "Status: (" + i + "/" + Parts + ")";
if (i < TotalProgressBar.Maximum)
{
TotalProgressBar.Value = i;
}
if (first == false)
{
TotalProgressLabel.Text = "(" + ProgressBarMegabyte + " MB / " + TotalMegabytes + " MB)";
first = true;
}
else
{
TotalProgressLabel.Text = "(" + ProgressBarMegabyte + " MB / " + TotalMegabytes + " MB)";
}
int Equation = Convert.ToInt32(Int32.Parse(ProgressBarMegabyte) +
Double.Parse(Convert.ToString(ProgressedMegabytes)));
ProgressBarMegabyte = Equation.ToString();
i++;
}
if (Int32.Parse(Parts) > 99)
{
await Task.Factory.StartNew(() =>
{
Process.Start(@"C:\Program Files\SoftwareStoreOffline\Setup-Files.part001.exe").WaitForExit();
});
}
else if (Int32.Parse(Parts) < 100)
{
await Task.Factory.StartNew(() =>
{
Process.Start(@"C:\Program Files\SoftwareStoreOffline\Setup-Files.part01.exe");
});
}
else if(Int32.Parse(Parts) < 10)
{
await Task.Factory.StartNew(() =>
{
Process.Start(@"C:\Program Files\SoftwareStoreOffline\Setup-Files.part1.exe");
});
}
}
private bool first = false;
private string MainDirectory = "C:\\Program Files\\SoftwareStoreOffline";
private string TotalBytes = string.Empty;
private async Task Download(string link, string Filename)
{
using (var client = new WebClient())
{
client.DownloadProgressChanged += Client_DownloadProgressChanged;
client.DownloadFileCompleted += Client_DownloadFileCompleted;
client.DownloadFileAsync(new Uri(link), Filename);
while (client.IsBusy)
{
await Task.Delay(10);
}
}
}
private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
if (e.Cancelled)
{
}
else if (e.Error != null)
{
}
else
{
}
}
private void Client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
TotalBytes = e.TotalBytesToReceive.ToString();
DownloadProgressBar.Value = e.ProgressPercentage;
}
private string Parts = string.Empty;
private string Database = string.Empty;
private string Version = string.Empty;
private async Task Initialize()
{
try
{
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreClientDownloader/master/OfflineDatabaseNumber.txt",
MainDirectory + "\\OfflineDatabaseNumber.txt");
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreClientDownloader/master/OfflineParts.txt",
MainDirectory + "\\OfflineParts.txt");
await Download(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreClientDownloader/master/OfflineVersion.txt",
MainDirectory + "\\OfflineVersion.txt");
Parts = File.ReadLines(MainDirectory + "\\OfflineParts.txt").First();
Database = File.ReadLines(MainDirectory + "\\OfflineDatabaseNumber.txt").First();
Version = File.ReadLines(MainDirectory + "\\OfflineVersion.txt").First();
}
catch (Exception dew)
{
Console.WriteLine(dew);
throw;
}
}
}
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统诊断;
使用系统图;
使用System.IO;
使用System.Linq;
Net系统;
使用系统文本;
使用System.Threading.Tasks;
使用System.Windows.Forms;
使用System.Xml;
命名空间SoftwareStoreClientDownloader
{
公共部分类脱机安装程序:表单
{
公共脱机安装程序()
{
初始化组件();
FormClosing+=离线安装程序\u FormClosing;
}
private void OfflineInstaller_FormClosing(对象发送方,FormClosingEventArgs e)
{
File.writealText(“C:\\Closed.txt”,“true”);
}
private void OfflineInstaller_加载(对象发送方,事件参数e)
{
如果(!Directory.Exists(“C:\\Program Files\\SoftwareStoreOffline”))
{
目录.CreateDirectory(“C:\\Program Files\\SoftwareStoreOffline”);
}
}
私有无效浏览按钮单击(对象发送者,事件参数e)
{
SaveFileDialog s=新建SaveFileDialog();
s、 DefaultExt=“iso”;
s、 AddExtension=false;
s、 CheckPathExists=true;
s、 ShowDialog();
尝试
{
BrowseFileTextBox.Text=s.FileName;
}
捕获(例外情况)
{
}
}
私有异步无效按钮1\u单击(对象发送方,事件参数e)
{
var i=2;
按钮1.启用=错误;
按钮1.Text=“初始化”;
等待初始化();
按钮1.Text=“下载”;
TotalProgressBar.max=Int32.Parse(部分);
if(Int32.Parse(Parts)>99)
{
等待下载(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline“+数据库+
“/master/SoftwareStore”+Version+“安装文件.part001.exe”,
MainDirectory+“\\”+“安装文件.part001.exe”);
}
其他的
{
等待下载(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline“+数据库+
“/master/SoftwareStore”+Version+“安装文件.part01.exe”,
MainDirectory+“\\”+“安装文件.part01.exe”);
}
var TotalProgressBytes=((Int32.Parse(TotalBytes)/1024d/1024d)*Int32.Parse(Parts));
var TotalMegabytes=TotalProgressBytes;
var ProgressedMegabytes=(Int32.Parse(TotalBytes)/1024d/1024d);
var ProgressBarMegabyte=string.Empty;
ProgressBarMegabyte=ProgressedMegabytes.ToString();
而(i99)
{
如果(i<10&&i<100)
{
等待下载(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline“+数据库+
“/master/SoftwareStore”+Version+“安装文件.part00”+i+“.rar”,
MainDirectory+“\\”+“安装文件.part00”+i+“.rar”);
}
否则,如果(i>10&&i<100)
{
等待下载(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline“+数据库+
“/master/SoftwareStore”+Version+“安装文件.part0”+i+“.rar”,
MainDirectory+“\\”+“安装文件.part0”+i+“.rar”);
}
否则,如果(i>99)
{
等待下载(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline“+数据库+
“/master/SoftwareStore”+Version+”安装文件。部分“+i+”.rar”,
MainDirectory+“\\”+“安装文件.part“+i+”.rar”);
}
}
else if(Int32.Parse(Parts)<10)
{
等待下载(
"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline“+数据库+
“/master/SoftwareStore”+Version+”安装文件。部分“+i+”.rar”,
MainDirectory+“\\”+“安装文件.part“+i+”.rar”);
}
DownloadProgressLabel.Text=“状态:(“+i+”/“+Parts+”)”;
如果(isting = int + double
double ProgressedMegabytes = 1.5;
string ProgressBarMegabyte = "83345603 .....................";
ProgressBarMegabyte = (Int32.Parse(ProgressBarMegabyte.TrimEnd('.')) + ProgressedMegabytes).ToString();
Console.WriteLine(ProgressBarMegabyte); // 83345604.5
int Equation = Convert.ToInt32(Int32.Parse(ProgressBarMegabyte)
+ Double.Parse(Convert.ToString(ProgressedMegabytes)));
ProgressBarMegabyte = Equation.ToString();
private async void button1_Click(object sender, EventArgs e)
{
var i = 2;
await Initialize();
var name = Parts > 99 ? "part001" : "part01";
await Download($"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline{Database}/master/SoftwareStore{Version}Setup-Files.{name}.exe", $"{MainDirectory}\\Setup-Files.{name}.exe");
var format = new string('0', Parts.ToString().Length)
while (i < Parts + 1)
{
await Download($"https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreOffline{Database}/master/SoftwareStore{Version}Setup-Files.part{i.ToString(format)}.rar", $"{MainDirectory}\\Setup-Files.{i.ToString(format)}.rar");
i++;
}
await Task.Factory.StartNew(() =>
{
Process.Start($@"C:\Program Files\SoftwareStoreOffline\Setup-Files.part{1.ToString(format)}.exe").WaitForExit();
});
}
private string MainDirectory = "C:\\Program Files\\SoftwareStoreOffline";
private async Task Download(string link, string Filename)
{
using (var client = new WebClient())
{
await client.DownloadFileTaskAsync(link, Filename);
}
}
private int Parts;
private string Database = string.Empty;
private string Version = string.Empty;
private async Task Initialize()
{
try
{
await Download("https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreClientDownloader/master/OfflineDatabaseNumber.txt", MainDirectory + "\\OfflineDatabaseNumber.txt");
await Download("https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreClientDownloader/master/OfflineParts.txt", MainDirectory + "\\OfflineParts.txt");
await Download("https://raw.githubusercontent.com/CNTowerGUN/SoftwareStoreClientDownloader/master/OfflineVersion.txt", MainDirectory + "\\OfflineVersion.txt");
Parts = int.Parse(File.ReadLines(MainDirectory + "\\OfflineParts.txt").First());
Database = File.ReadLines(MainDirectory + "\\OfflineDatabaseNumber.txt").First();
Version = File.ReadLines(MainDirectory + "\\OfflineVersion.txt").First();
}
catch (Exception dew)
{
Console.WriteLine(dew);
throw;
}
}