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("还原点创建失败!");
                    }
                }
            }
        }
Esempio n. 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_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地址的客户端!");
            }
        }
Esempio n. 3
0
        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();
                }
            }
        }