Exemple #1
0
        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("工作站删除完成!");
                        }
                    }
                }
            }
        }
Exemple #2
0
        private void 应用button_Click(object sender, EventArgs e)
        {
            if ((称textBox.Text.Trim() == "") || (MACtextBox.Text.Trim() == "") || (工作目录textBox.Text.Trim() == ""))
            {
                MessageBox.Show("请填写完整的信息!");
                return;
            }

            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   = "";

            if (client_disk_list_id == "")
            {
                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 + "' and client_id != '" + client_id + "';";
                    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;



                        //string addClientSql = "udpate CLIENT (client_id,client_name,client_mac,client_work_path,client_description,client_group_id,client_disk_list_id,client_enable) values ('" + client_id + "','" + client_name + "','" + client_mac + "','" + client_work_path + "','" + client_description + "','" + client_group_id + "','" + client_disk_list_id + "','"  + client_enable + "');";
                        string updateClientSql = "update CLIENT set client_name='" + client_name + "',client_mac='" + client_mac + "',client_work_path='" + client_work_path + "',client_description='" + client_description + "',client_group_id='" + client_group_id + "',client_disk_list_id='" + client_disk_list_id + "',client_enable='" + client_enable + "' where client_id='" + client_id + "';";

                        sh.ExecuteScalar(updateClientSql);
                        //删除原先已经创建的磁盘以及数据库中的内容
                        string deleteClientDiskList = "delete from CLIENT_DISK_LIST where client_disk_list_id='" + client_disk_list_id + "';";

                        DataTable dtClintDiskList = sh.Select("select * from CLIENT_DISK_LIST where client_disk_list_id = '" + client_disk_list_id + "';");
                        foreach (DataRow row in dtClintDiskList.Rows)
                        {
                            string    sqlClientDiskName = "select * from VDISK_TEMPLET where disk_id='" + row["disk_id"] + "';";
                            DataTable dtClientDisk      = sh.Select(sqlClientDiskName);
                            foreach (DataRow rows in dtClientDisk.Rows)
                            {
                                DiskManagementData ParamObj = new DiskManagementData(); // TODO: 初始化为适当的值
                                ParamObj.DevicePath = client_work_path + "\\" + rows["disk_name"].ToString() + "-" + client_mac + ".vhdx";;
                                ParamObj.TargetName = rows["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(deleteClientDiskList);



                        int    diskSort          = 0;
                        string addClientDiskList = "";
                        foreach (VdiskTemplate v in tovdiskTempletList)
                        {
                            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);
                        }


                        conn.Close();
                        this.Close();


                        //创建客户端启动脚本


                        //创建客户端启动盘
                        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 = 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;



                        UpdateGrid(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)
        {
            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("系统中没有磁盘!");
            }
        }