private void 除工作站ToolStripMenuItem_Click(object sender, EventArgs e) { string client_disk_list_id = ""; string client_word_path = ""; string client_mac = ""; string iscsiURL; string username; string password; IniFile ini = new IniFile(Environment.CurrentDirectory + "\\setting.ini"); iscsiURL = ini.ReadString("IscsiServer", "URL", ""); username = ini.ReadString("IscsiServer", "USERNAME", ""); password = ini.ReadString("IscsiServer", "PASSWORD", ""); if (工作站dataGridView.Rows.Count != 0) { MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("确定要删除选中的工作站?", "删除工作站", messButton); if (dr == DialogResult.OK) { using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); string selectDiskListId = "select * from CLIENT where client_id = '" + 工作站dataGridView.CurrentRow.Cells["IDColumn"].Value + "';"; string deleteClient = "delete from CLIENT where client_id = '" + 工作站dataGridView.CurrentRow.Cells["IDColumn"].Value + "';"; DataTable dtGroup = sh.Select(selectDiskListId); foreach (DataRow row in dtGroup.Rows) { client_disk_list_id = row["client_disk_list_id"].ToString(); client_word_path = row["client_work_path"].ToString(); client_mac = row["client_mac"].ToString(); } string deleteDiskList = "delete from CLIENT_DISK_LIST where client_disk_list_id = '" + client_disk_list_id + "';"; string selectDiskList = "select * from CLIENT_DISK_LIST where client_disk_list_id = '" + client_disk_list_id + "';"; DataTable dtDiskList = sh.Select(selectDiskList); //删除磁盘文件 foreach (DataRow row in dtDiskList.Rows) { string selectDisk = "select * from VDISK_TEMPLET where disk_id = '" + row["disk_id"].ToString() + "';"; DataTable dtDisk = sh.Select(selectDisk); foreach (DataRow rowDisk in dtDisk.Rows) { DiskManagementData ParamObj = new DiskManagementData(); // TODO: 初始化为适当的值 ParamObj.DevicePath = client_word_path + "\\" + rowDisk["disk_name"].ToString() + "-" + client_mac + ".vhdx";; ParamObj.TargetName = rowDisk["disk_name"].ToString() + "-" + client_mac; ParamObj.serverURL = iscsiURL; ParamObj.Username = username; ParamObj.Password = password; bool actual; actual = DiskManager.RemoveDisk(ParamObj); if (actual == true) { //MessageBox.Show("磁盘删除成功!"); } } } sh.ExecuteScalar(deleteDiskList); sh.ExecuteScalar(deleteClient); for (int i = 0; i < clientList.Count; i++) { if (clientList[i].ClientMac == client_mac) { clientList.Remove(clientList[i]); } } this.工作站dataGridView.AutoGenerateColumns = false; 工作站dataGridView.DataSource = null; 工作站dataGridView.DataSource = clientList; TreeNode node = 分组treeView.SelectedNode; node.Remove(); conn.Close(); MessageBox.Show("工作站删除完成!"); } } } } }
private void 应用button_Click(object sender, EventArgs e) { if ((称textBox.Text.Trim() == "") || (MACtextBox.Text.Trim() == "") || (工作目录textBox.Text.Trim() == "")) { MessageBox.Show("请填写完整的信息!"); return; } string client_id = System.Guid.NewGuid().ToString("N"); string client_name = 称textBox.Text.Trim(); string client_mac = MACtextBox.Text.Trim(); string client_work_path = 工作目录textBox.Text.Trim(); string client_description = 备注textBox.Text.Trim(); string client_group_id = ""; string client_group_tag = ""; string client_disk_list_id = System.Guid.NewGuid().ToString("N"); if (启用工作站checkBox.Checked == true) { client_enable = 1; } else { client_enable = 0; } using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); string tempSelectedText = 分组comboBox.Text; DataTable dt = sh.Select("select * from CLIENT_GROUP where client_group_name = '" + tempSelectedText + "';"); if (dt.Rows.Count == 0) { client_group_id = "未分组"; client_group_tag = "未分组"; } else { foreach (DataRow row in dt.Rows) { client_group_id = row["client_group_id"].ToString(); client_group_tag = row["client_group_name"].ToString(); } } conn.Close(); } } //判断是否有重复的MAC地址,如果有则不允许添加 bool tempMacOnly = false; using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); string tempMacString = "select count(*) from CLIENT where client_mac = '" + client_mac + "';"; int count = int.Parse(sh.ExecuteScalar(tempMacString).ToString()); if (count == 0) { tempMacOnly = true; } else { tempMacOnly = false; } conn.Close(); } } if (tempMacOnly == true) { using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); //更新主页datagrid的source Client client = new Client(); client.ClientId = client_id; client.ClientName = client_name; client.ClientMac = client_mac; client.clientWorkPath = client_work_path; client.clientDescription = client_description; client.ClientSuperEnable = "0"; client.ClientEnable = "1"; string addClientSql = "insert into CLIENT (client_id,client_name,client_mac,client_work_path,client_description,client_group_id,client_disk_list_id,client_enable,client_super_enable) values ('" + client_id + "','" + client_name + "','" + client_mac + "','" + client_work_path + "','" + client_description + "','" + client_group_id + "','" + client_disk_list_id + "','" + client_enable + "','0');"; sh.ExecuteScalar(addClientSql); int diskSort = 0; string addClientDiskList = ""; string diskId = ""; foreach (VdiskTemplate v in tovdiskTempletList) { diskId = v.DiskId; addClientDiskList = "insert into CLIENT_DISK_LIST (client_disk_list_id,disk_id,disk_sort) values ('" + client_disk_list_id + "','" + v.DiskId + "','" + diskSort++ + "');"; sh.ExecuteScalar(addClientDiskList); } //创建客户端启动脚本 //创建客户端启动盘 foreach (VdiskTemplate v in tovdiskTempletList) { //获取最新的还原点的磁盘路径 string parentPointPath = ""; string sort = "0"; DataTable rs = sh.Select("select * from VDISK_RESTORE_POINT where disk_id = '" + v.DiskId + "';"); int count = rs.Rows.Count; if (count != 0) { foreach (DataRow rows in rs.Rows) { if (float.Parse(sort) < float.Parse(rows["vdisk_restore_point_sort"].ToString())) { sort = rows["vdisk_restore_point_sort"].ToString(); parentPointPath = rows["vdisk_restore_point_path"].ToString(); } } } else { parentPointPath = v.DiskPath + v.DiskName + ".vhdx"; } //创建磁盘文件 DiskManagementData ParamObj = new DiskManagementData(); // TODO: 初始化为适当的值 ParamObj.VhdxType = 4; //动态盘 ParamObj.DevicePath = client_work_path + "\\" + v.DiskName + "-" + client_mac + ".vhdx"; ParamObj.TargetName = v.DiskName + "-" + client_mac; ParamObj.DiskSize = ushort.Parse("10"); ParamObj.TargetIQN = "HstecsClient." + v.DiskName + "-" + client_mac; //ParamObj.ParentPath = v.DiskPath + v.DiskName + ".vhdx"; ParamObj.ParentPath = parentPointPath; ParamObj.serverURL = iscsiURL; ParamObj.Username = username; ParamObj.Password = password; DiskManager.CreateVhdxDisk(ParamObj); } //更新tree及主页datagrid TreeNode node = new TreeNode(client_name, IconIndexes.computer, IconIndexes.computer); node.Tag = client_name; node.Text = client_name; conn.Close(); this.Close(); UpdateTree(node, client_group_tag, client); MessageBox.Show("工作站添加成功!"); } } } else { MessageBox.Show("已存在指定MAC地址的客户端!"); } }
private void 还原button_Click(object sender, EventArgs e) { DataRowView drv = (DataRowView)磁盘comboBox.SelectedItem; string diskName = Convert.ToString(drv.Row["Text"]); if (diskName == "请选择") { return; } if (vDiskParent.vdiskRestorePoint == null || vDiskParent.vdiskRestorePoint.Count == 0) { MessageBox.Show("磁盘没有还原点!"); return; } MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("确定要退回到最近的还原点吗?", "还原", messButton); if (dr == DialogResult.OK) { using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); VdiskRestorePoint tempPoint = new VdiskRestorePoint(); float tempPointSort = 0; foreach (VdiskRestorePoint p in vDiskParent.vdiskRestorePoint) { if (p.VdiskRestorePointSort > tempPointSort) { tempPointSort = p.VdiskRestorePointSort; } } foreach (VdiskRestorePoint p in vDiskParent.vdiskRestorePoint) { if (p.VdiskRestorePointSort == tempPointSort) { tempPoint = p; } } string vdisk_restore_point_id = tempPoint.VdiskRestorePointId; string vdisk_resotre_point_name = tempPoint.VdiskResotrePointName; string vdisk_restore_point_path = tempPoint.VdiskRestorePointPath; string deleteSql = "DELETE from VDISK_RESTORE_POINT WHERE vdisk_restore_point_id = '" + vdisk_restore_point_id + "'"; vDiskParent.vdiskRestorePoint.Remove(tempPoint); 还原点dataGridView.AutoGenerateColumns = false; 还原点dataGridView.DataSource = vDiskParent.vdiskRestorePoint.ToArray(); sh.ExecuteScalar(deleteSql); conn.Close(); DiskManagementData ParamObj = new DiskManagementData(); // TODO: 初始化为适当的值 ParamObj.DevicePath = tempPoint.VdiskRestorePointPath; ParamObj.TargetName = tempPoint.VdiskResotrePointName; ParamObj.serverURL = iscsiURL; ParamObj.Username = username; ParamObj.Password = password; bool actual; actual = DiskManager.RemoveDisk(ParamObj); if (actual == true) { MessageBox.Show("磁盘删除成功!"); } } } } }
private void 新增button_Click(object sender, EventArgs e) { DataRowView drv = (DataRowView)磁盘comboBox.SelectedItem; string diskName = Convert.ToString(drv.Row["Text"]); if (diskName == "请选择") { return; } MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("确定要创建还原点吗?", "创建还原点", messButton); if (dr == DialogResult.OK) { DateTime dt = DateTime.Now; string time = string.Format("{0:yyyyMMddHHmmssffff}", dt); DiskManagementData ParamObj = new DiskManagementData(); ParamObj.VhdxType = 4; if (vDiskParent.vdiskRestorePoint == null || vDiskParent.vdiskRestorePoint.Count == 0) { ParamObj.DevicePath = vDiskParent.DiskPath + vDiskParent.DiskName + "-" + time + ".vhdx"; ParamObj.TargetName = vDiskParent.DiskName + "-" + time; ParamObj.DiskSize = ushort.Parse(vDiskParent.DiskSize.ToString()); ParamObj.TargetIQN = "HstecsTemplet." + vDiskParent.DiskName + "-" + time; ParamObj.ParentPath = vDiskParent.DiskPath + vDiskParent.DiskName + ".vhdx"; ParamObj.serverURL = iscsiURL; ParamObj.Username = username; ParamObj.Password = password; var dic = new Dictionary <string, object>(); dic["vdisk_restore_point_id"] = System.Guid.NewGuid().ToString("N"); dic["disk_id"] = vDiskParent.DiskId; dic["vdisk_restore_point_create_time"] = time; dic["vdisk_resotre_point_name"] = vDiskParent.DiskName + "-" + time; dic["vdisk_restore_point_description"] = time; dic["vdisk_restore_point_path"] = vDiskParent.DiskPath + vDiskParent.DiskName + "-" + time + ".vhdx"; dic["vdisk_restore_point_sort"] = time; bool actual; actual = DiskManager.CreateVhdxDisk(ParamObj); if (actual == true) { using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); sh.Insert("VDISK_RESTORE_POINT", dic); VdiskRestorePoint tempPoint = new VdiskRestorePoint(); tempPoint.VdiskResotrePointName = dic["vdisk_resotre_point_name"].ToString(); tempPoint.VdiskRestorePointCreateTime = dic["vdisk_restore_point_create_time"].ToString(); tempPoint.VdiskRestorePointDescription = dic["vdisk_restore_point_create_time"].ToString(); tempPoint.VdiskRestorePointPath = dic["vdisk_restore_point_path"].ToString(); tempPoint.VdiskRestorePointId = dic["vdisk_restore_point_id"].ToString(); vDiskParent.AddVdiskRestorePoint(tempPoint); 还原点dataGridView.AutoGenerateColumns = false; 还原点dataGridView.DataSource = vDiskParent.vdiskRestorePoint.ToArray(); conn.Close(); } } MessageBox.Show("磁盘添加成功!"); } else { MessageBox.Show("磁盘添加失败!"); } } else { VdiskRestorePoint tempPoint = new VdiskRestorePoint(); float tempPointSort = 0; foreach (VdiskRestorePoint p in vDiskParent.vdiskRestorePoint) { if (p.VdiskRestorePointSort > tempPointSort) { tempPointSort = p.VdiskRestorePointSort; } } foreach (VdiskRestorePoint p in vDiskParent.vdiskRestorePoint) { if (p.VdiskRestorePointSort == tempPointSort) { tempPoint = p; } } ParamObj.DevicePath = vDiskParent.DiskPath + vDiskParent.DiskName + "-" + time + ".vhdx"; ParamObj.TargetName = vDiskParent.DiskName + "-" + time; ParamObj.DiskSize = ushort.Parse(vDiskParent.DiskSize.ToString()); ParamObj.TargetIQN = "HstecsTemplet." + vDiskParent.DiskName + "-" + time; //ParamObj.ParentPath = vDiskParent.DiskPath + vDiskParent.DiskName + ".vhdx"; ParamObj.ParentPath = tempPoint.VdiskRestorePointPath; ParamObj.serverURL = iscsiURL; ParamObj.Username = username; ParamObj.Password = password; var dic = new Dictionary <string, object>(); dic["vdisk_restore_point_id"] = System.Guid.NewGuid().ToString("N"); dic["disk_id"] = vDiskParent.DiskId; dic["vdisk_restore_point_create_time"] = time; dic["vdisk_resotre_point_name"] = vDiskParent.DiskName + "-" + time; dic["vdisk_restore_point_description"] = time; dic["vdisk_restore_point_path"] = vDiskParent.DiskPath + vDiskParent.DiskName + "-" + time + ".vhdx"; dic["vdisk_restore_point_sort"] = time; bool actual; actual = DiskManager.CreateVhdxDisk(ParamObj); if (actual == true) { using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); sh.Insert("VDISK_RESTORE_POINT", dic); VdiskRestorePoint tempPoints = new VdiskRestorePoint(); tempPoints.VdiskResotrePointName = dic["vdisk_resotre_point_name"].ToString(); tempPoints.VdiskRestorePointCreateTime = dic["vdisk_restore_point_create_time"].ToString(); tempPoints.VdiskRestorePointDescription = dic["vdisk_restore_point_create_time"].ToString(); tempPoints.VdiskRestorePointSort = float.Parse(dic["vdisk_restore_point_sort"].ToString()); tempPoints.VdiskRestorePointPath = dic["vdisk_restore_point_path"].ToString(); tempPoints.VdiskRestorePointId = dic["vdisk_restore_point_id"].ToString(); vDiskParent.AddVdiskRestorePoint(tempPoints); 还原点dataGridView.AutoGenerateColumns = false; 还原点dataGridView.DataSource = vDiskParent.vdiskRestorePoint.ToArray(); conn.Close(); } } MessageBox.Show("还原点创建成功!"); } else { MessageBox.Show("还原点创建失败!"); } } } }
private void 确定button_Click(object sender, EventArgs e) { if (this.磁盘名称textBox.Text.Replace(" ", "") == "" || this.磁盘容量textBox.Text.Replace(" ", "") == "" || this.像文件textBox.Text.Replace(" ", "") == "") { MessageBox.Show("请填写完整的信息!"); return; } if (!TextInputStringValidator.IsEnglishWithNum(this.磁盘名称textBox.Text.Replace(" ", ""))) { MessageBox.Show("磁盘名需以英文字母、数字、_组成!"); return; } if (!TextInputStringValidator.IsNumber(this.磁盘容量textBox.Text.Replace(" ", ""))) { MessageBox.Show("磁盘大小只能为数字!"); return; } string diskName = this.磁盘名称textBox.Text.Replace(" ", ""); int diskSize = int.Parse(this.磁盘容量textBox.Text.Replace(" ", "")); string diskPath = this.像文件textBox.Text.Replace(" ", ""); int diskType; if (this.稀疏文件checkBox.Checked) { diskType = 3; } else { diskType = 2; } if (diskSize < 1 || diskSize > 2048) { MessageBox.Show("磁盘大小应介于1-2048G之间!"); return; } for (int i = 0; i < this.vdiskTempletList.Count; i++) { if (vdiskTempletList[i].DiskName == diskName) { MessageBox.Show("磁盘名称已存在!"); return; } } var dic = new Dictionary <string, object>(); dic["disk_name"] = diskName; dic["disk_size"] = diskSize; dic["disk_path"] = diskPath + "\\"; dic["disk_type"] = diskType; dic["disk_id"] = System.Guid.NewGuid().ToString("N"); //插入磁盘数据到数据库 using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); sh.Insert("VDISK_TEMPLET", dic); VdiskTemplate vdiskTemplet = new VdiskTemplate(); vdiskTemplet.DiskId = dic["disk_id"].ToString(); vdiskTemplet.DiskName = dic["disk_name"].ToString(); vdiskTemplet.DiskSize = int.Parse(dic["disk_size"].ToString()); vdiskTemplet.DiskPath = dic["disk_path"].ToString(); vdiskTemplet.DiskType = int.Parse(dic["disk_type"].ToString()); vdiskTempletList.Add(vdiskTemplet); parentDataGridView.AutoGenerateColumns = false; parentDataGridView.DataSource = vdiskTempletList.ToArray(); //创建磁盘文件 DiskManagementData ParamObj = new DiskManagementData(); // TODO: 初始化为适当的值 if (this.稀疏文件checkBox.Checked) { ParamObj.VhdxType = 3; //动态盘 } else { ParamObj.VhdxType = 2; //固定大小 } ParamObj.DevicePath = dic["disk_path"].ToString() + dic["disk_name"].ToString() + ".vhdx"; ParamObj.TargetName = dic["disk_name"].ToString(); ParamObj.DiskSize = ushort.Parse(dic["disk_size"].ToString()); ParamObj.TargetIQN = "HstecsTemplet." + dic["disk_name"].ToString(); ParamObj.ParentPath = dic["disk_path"].ToString() + dic["disk_name"].ToString() + ".vhdx"; ParamObj.serverURL = iscsiURL; ParamObj.Username = username; ParamObj.Password = password; bool actual; actual = DiskManager.CreateVhdxDisk(ParamObj); if (actual == true) { MessageBox.Show("磁盘添加成功!"); } else { MessageBox.Show("磁盘添加失败!"); } conn.Close(); this.Close(); } } }
private void 除button_Click(object sender, EventArgs e) { bool hasClientUseTheDisk = false; bool hasPointOfTheDisk = false; string diskIds = this.磁盘管理dataGridView.SelectedRows[0].Cells["diskId"].Value.ToString(); using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); DataTable dtClientUseDisk = sh.Select("select * from CLIENT_DISK_LIST where disk_id='" + diskIds + "';"); DataTable dtPointOfTheDisk = sh.Select("select * from VDISK_RESTORE_POINT where disk_id='" + diskIds + "';"); if (dtClientUseDisk.Rows.Count > 0) { hasClientUseTheDisk = false; } else { hasClientUseTheDisk = true; } if (dtPointOfTheDisk.Rows.Count > 0) { hasPointOfTheDisk = false; } else { hasPointOfTheDisk = true; } conn.Close(); } } if (!hasClientUseTheDisk) { MessageBox.Show("存在使用本磁盘的工作站,请先将工作站磁盘设置为空或设置为其他工作站!"); return; } if (!hasPointOfTheDisk) { MessageBox.Show("本磁盘存在还原点,请先将所有还原点删除后再删除本磁盘!"); return; } if (vdiskTempletList.Count != 0) { MessageBoxButtons messButton = MessageBoxButtons.OKCancel; DialogResult dr = MessageBox.Show("确定要删除选中的磁盘吗?", "删除磁盘", messButton); if (dr == DialogResult.OK) { //删除选中的磁盘 using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); //int at = this.skinDataGridViewVdiskAdd.CurrentRow.Index; string diskId = this.磁盘管理dataGridView.SelectedRows[0].Cells["diskId"].Value.ToString(); string diskName = this.磁盘管理dataGridView.SelectedRows[0].Cells["diskName"].Value.ToString(); string diskPath = this.磁盘管理dataGridView.SelectedRows[0].Cells["diskPath"].Value.ToString(); string deleteSql = "DELETE from VDISK_TEMPLET WHERE disk_id = '" + diskId + "'"; for (int i = 0; i < vdiskTempletList.Count; i++) { if (vdiskTempletList[i].DiskId == diskId) { vdiskTempletList.RemoveAt(i); } } this.磁盘管理dataGridView.AutoGenerateColumns = false; this.磁盘管理dataGridView.DataSource = vdiskTempletList.ToArray(); sh.ExecuteScalar(deleteSql); DiskManagementData ParamObj = new DiskManagementData(); // TODO: 初始化为适当的值 ParamObj.DevicePath = diskPath + diskName + ".vhdx"; ParamObj.TargetName = diskName; ParamObj.serverURL = iscsiURL; ParamObj.Username = username; ParamObj.Password = password; bool actual; actual = DiskManager.RemoveDisk(ParamObj); if (actual == true) { MessageBox.Show("磁盘删除成功!"); } conn.Close(); } } } else { return; } } else { MessageBox.Show("系统中没有磁盘!"); } }
private void 导入button_Click(object sender, EventArgs e) { string devicePath = ""; string fileName = ""; string fileNameWithOutEx = ""; string fileDirectoryName = ""; OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { fileName = System.IO.Path.GetFileName(dialog.FileName); fileNameWithOutEx = System.IO.Path.GetFileNameWithoutExtension(dialog.FileName); devicePath = System.IO.Path.GetFullPath(dialog.FileName); fileDirectoryName = System.IO.Path.GetDirectoryName(dialog.FileName) + "\\"; for (int i = 0; i < this.vdiskTempletList.Count; i++) { if (vdiskTempletList[i].DiskName == fileNameWithOutEx) { MessageBox.Show("磁盘名称已存在!"); return; } } DiskManagementData ParamObj = new DiskManagementData(); // TODO: 初始化为适当的值 ParamObj.DevicePath = devicePath; ParamObj.TargetName = fileNameWithOutEx; ParamObj.TargetIQN = "HstecsTemplet." + fileNameWithOutEx; ParamObj.serverURL = iscsiURL; ParamObj.Username = username; ParamObj.Password = password; bool actual; actual = DiskManager.ImportVhdxDisk(ParamObj); if (actual == true) { //获取虚拟磁盘的类型和大小 ManagementObject DiskObj = null; if (!DiskManager.GetVirtualDisk(@devicePath, ref DiskObj, iscsiURL, username, password)) { throw new Exception(Extension.GetEnumDescription(ReturnCode.RC_GetDisk)); } else { var dic = new Dictionary <string, object>(); dic["disk_name"] = fileNameWithOutEx; dic["disk_size"] = uint.Parse(DiskObj.GetPropertyValue("Size").ToString()) / 1024; dic["disk_path"] = fileDirectoryName; dic["disk_type"] = uint.Parse(DiskObj.GetPropertyValue("Type").ToString()); dic["disk_id"] = System.Guid.NewGuid().ToString("N"); using (SQLiteConnection conn = new SQLiteConnection("data source=nodisk.db")) { using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = conn; conn.Open(); SQLiteHelper sh = new SQLiteHelper(cmd); sh.Insert("VDISK_TEMPLET", dic); VdiskTemplate vdiskTemplet = new VdiskTemplate(); vdiskTemplet.DiskId = dic["disk_id"].ToString(); vdiskTemplet.DiskName = dic["disk_name"].ToString(); vdiskTemplet.DiskSize = int.Parse(dic["disk_size"].ToString()); vdiskTemplet.DiskPath = dic["disk_path"].ToString(); vdiskTemplet.DiskType = int.Parse(dic["disk_type"].ToString()); vdiskTempletList.Add(vdiskTemplet); this.磁盘管理dataGridView.AutoGenerateColumns = false; this.磁盘管理dataGridView.DataSource = vdiskTempletList.ToArray(); conn.Close(); } } MessageBox.Show("磁盘添加成功!"); } } else { MessageBox.Show("磁盘添加失败!"); } } }