コード例 #1
0
ファイル: FTPManager.cs プロジェクト: Genjo15/FTPManager
        /****************************************\
         * Duplicate contextMenuItemClick event *
         *    - Duplicate selected region       *
        \****************************************/
        private void DuplicateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (FTPTreeView.SelectedNode != null && FTPTreeView.SelectedNode.Nodes.Count == 0)
            {
                Region duplicatedRegion = new Region();

                /* Create service */
                FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient();

                /* Get region to duplicate */
                Region regionToDuplicate = new Region();
                foreach (Region element in _RegionsList)
                {
                    if (element.Get_RegionName().Equals(FTPTreeView.SelectedNode.Text.ToString())) //if (element.Get_RegionName().Equals(FTPListDataGridView.CurrentCell.Value))
                    {
                        regionToDuplicate = element;
                        break;
                    }
                }

                /* Clone it */
                duplicatedRegion.Clone(regionToDuplicate);
                duplicatedRegion.Set_RegionNameForClone();

                /* Add it to the list of regions */
                _RegionsList.Add(duplicatedRegion);

                /* Add it in DB */
                int serverID = service.Get_server_id(duplicatedRegion.Get_Provider(), duplicatedRegion.Get_FtpHost(), duplicatedRegion.Get_Login(), duplicatedRegion.Get_Password());
                int idFrequency;
                int idDay;
                switch (duplicatedRegion.Get_RecoveryFrequency())
                {
                    case "None": idFrequency = 5; break;
                    case "Daily": idFrequency = 1; break;
                    case "Weekly": idFrequency = 2; break;
                    case "Monthly": idFrequency = 3; break;
                    case "Yearly": idFrequency = 4; break;
                    default: idFrequency = 5; break;
                }
                switch (duplicatedRegion.Get_RecoveryDay())
                {
                    case "None": idDay = 8; break;
                    case "Monday": idDay = 1; break;
                    case "Tuesday": idDay = 2; break;
                    case "Wednesday": idDay = 3; break;
                    case "Thursday": idDay = 4; break;
                    case "Friday": idDay = 5; break;
                    case "Saturday": idDay = 6; break;
                    case "Sunday": idDay = 7; break;
                    default: idDay = 8; break;
                }
                service.Add_region(serverID, duplicatedRegion.Get_RegionName(), duplicatedRegion.Get_FileMask(), duplicatedRegion.Get_TargetDirectory(), idFrequency, idDay);

                /* Refresh List of FTP */
                //FTPListDataGridView.DataSource = null;
                FillFTPTreeView(); //FillFtpListDataGridView();
                FTPTreeView.SelectedNode = null; //FTPListDataGridView.ClearSelection();

                /* Display result */
                KryptonMessageBox.Show("Region Duplicated !", "Cloned",
                     MessageBoxButtons.OK,
                     MessageBoxIcon.Information);

                /* Close service */
                service.Close();
            }
        }
コード例 #2
0
ファイル: FTPManager.cs プロジェクト: Genjo15/FTPManager
        /********************************************************\
         * Create FTP (OK button click)                         *
         * - Create/Edit FTP (depending on the context)         *
         * - CheckFields : check if mandatory fields are filled *
        \********************************************************/
        private void OkPictureBox_Click(object sender, EventArgs e)
        {
            /* Check if fields are OK */
            if (CheckFields())
            {
                /* Create service */
                FTPWebService.ftpSoapClient service = new FTPWebService.ftpSoapClient();

                /* CASE 1 : CREATION */
                if (((string)OkPictureBox.Tag).Equals(""))
                {
                    /* Check if server exists (Provider|Server Adress|Login|Password) */
                    int serverID = service.Get_server_id(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                    if (serverID == 0)
                    {
                        /* Create server if not exists then get id_server */
                        service.Add_server(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                        serverID = service.Get_server_id(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                    }

                    /* Set idFrequency and idDay */
                    int idFrequency;
                    int idDay;
                    string frequency;
                    string day;
                    switch (RecoveryFrequencyComboBox.Text)
                    {
                        case "None": idFrequency = 5; frequency = "None"; break;
                        case "Daily": idFrequency = 1; frequency = "Daily"; break;
                        case "Weekly": idFrequency = 2; frequency = "Weekly"; break;
                        case "Monthly": idFrequency = 3; frequency = "Monthly"; break;
                        case "Yearly": idFrequency = 4; frequency = "Yearly"; break;
                        default: idFrequency = 5; frequency = "None"; break;
                    }
                    switch (RecoveryDayComboBox.Text)
                    {
                        case "None": idDay = 8; day = "None"; break;
                        case "Monday": idDay = 1; day = "Monday"; break;
                        case "Tuesday": idDay = 2; day = "Tuesday"; break;
                        case "Wednesday": idDay = 3; day = "Wednesday"; break;
                        case "Thursday": idDay = 4; day = "Thursday"; break;
                        case "Friday": idDay = 5; day = "Friday"; break;
                        case "Saturday": idDay = 6; day = "Saturday"; break;
                        case "Sunday": idDay = 7; day = "Sunday"; break;
                        default: idDay = 8; day = "None"; break;
                    }

                    /* Insert region */
                    service.Add_region(serverID, RegionNameTextBox.Text, FileMaskTextBox.Text, _TargetPathTooltip.GetToolTip(TargetDirectoryButton), idFrequency, idDay);

                    /* Add new region to the list */
                    _RegionsList.Add(new Region(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text, RegionNameTextBox.Text, _TargetPathTooltip.GetToolTip(TargetDirectoryButton), FileMaskTextBox.Text, frequency, day));

                    /* Refresh List of FTP */
                    //FTPListDataGridView.DataSource = null;
                    FillFTPTreeView();//FillFtpListDataGridView();

                    /* Display result */
                    KryptonMessageBox.Show("FTP Created !", "Saved",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
                }

                /* CASE 2 : EDIT */
                else if (!((string)OkPictureBox.Tag).Equals(""))
                {
                    /* Check if server exists (Provider|Server Adress|Login|Password) */
                    int serverID = service.Get_server_id(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                    if (serverID == 0)
                    {
                        /* Create server if not exists then get id_server */
                        service.Add_server(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                        serverID = service.Get_server_id(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text);
                    }

                    /* Set idFrequency and idDay */
                    int idFrequency;
                    int idDay;
                    switch (RecoveryFrequencyComboBox.Text)
                    {
                        case "None": idFrequency = 5; break;
                        case "Daily": idFrequency = 1; break;
                        case "Weekly": idFrequency = 2; break;
                        case "Monthly": idFrequency = 3; break;
                        case "Yearly": idFrequency = 4; break;
                        default: idFrequency = 5; break;
                    }
                    switch (RecoveryDayComboBox.Text)
                    {
                        case "None": idDay = 8; break;
                        case "Monday": idDay = 1; break;
                        case "Tuesday": idDay = 2; break;
                        case "Wednesday": idDay = 3; break;
                        case "Thursday": idDay = 4; break;
                        case "Friday": idDay = 5; break;
                        case "Saturday": idDay = 6; break;
                        case "Sunday": idDay = 7; break;
                        default: idDay = 8; break;
                    }

                    /* Update region */
                    service.Update_region((string)OkPictureBox.Tag, serverID, RegionNameTextBox.Text, FileMaskTextBox.Text, _TargetPathTooltip.GetToolTip(TargetDirectoryButton), idFrequency, idDay);

                    /* Remove old region from the list */
                    foreach (Region element in _RegionsList)
                    {
                        if (element.Get_RegionName().Equals((string)OkPictureBox.Tag))
                        {
                            _RegionsList.Remove(element);
                            break;
                        }
                    }

                    /* Add new one */
                    _RegionsList.Add(new Region(ProviderTextBox.Text, ServerAddressTextBox.Text, LoginTextBox.Text, PasswordTextBox.Text, RegionNameTextBox.Text, _TargetPathTooltip.GetToolTip(TargetDirectoryButton), FileMaskTextBox.Text, RecoveryFrequencyComboBox.Text, RecoveryDayComboBox.Text));

                    /* Refresh List of FTP */
                    //FTPListDataGridView.DataSource = null;
                    FillFTPTreeView();//FillFtpListDataGridView();

                    /* Display result */
                    KryptonMessageBox.Show("FTP updated !", "Updated",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
                }

                /* Finally, End Edit */
                EndEdit();

                /* Close service */
                service.Close();
            }
        }