コード例 #1
0
 public ModifyProjectForm(string fileName, string projectName)
 {
     InitializeComponent();
     this.fileName    = fileName;
     this.projectName = projectName;
     projectText.Text = this.projectName;
     setCategoryCombo();
     setTypeSelCombo();
     setWorkCombo();
     projectText.Enabled = false;
     workAtText.Enabled  = false;
     namespaceTree       = new SetNamespaceTreeView(namespaceTreeView, fileName, projectName);
     setDirectory();
     setClassFile();
 }
コード例 #2
0
        private void doBtn_Click(object sender, EventArgs e)
        {
            AccessSqlite sql    = new AccessSqlite();
            ManageFile   mf     = new ManageFile();
            int          result = -2;
            string       path;

            if (categoryCombo.SelectedItem == null)
            {
                MessageBox.Show("Select a Category for this work.");
                return;
            }
            else if (workAtText.Text == "")
            {
                string msg = "";
                if (categoryCombo.SelectedItem.ToString() == "Class")
                {
                    msg = "Click a Namespace in View for this work.";
                }
                else if (categoryCombo.SelectedItem.ToString() == "Field")
                {
                    msg = "Click a Class in View for this work.";
                }
                MessageBox.Show(msg);
                return;
            }
            else if (nameText.Text == "")
            {
                MessageBox.Show("Input a name in Name Textbox for this work.");
                return;
            }
            else if (CheckCharacter.checkNamespace(nameText.Text) != 0)
            {
                return;
            }
            else if (workCombo.SelectedItem == null)
            {
                MessageBox.Show("Select a work in Work Combo box for this work.");
                return;
            }
            else if (categoryCombo.SelectedItem.ToString() == "Namespace" && workCombo.SelectedItem.ToString() == "Create")
            {
                result = sql.insertNamespace(projectName, nameText.Text);
                if (result == 0)
                {
                    namespaceTree = new SetNamespaceTreeView(namespaceTreeView, fileName, projectName);
                    namespaceTree.expandNode(nameText.Text);
                    path = nameText.Text.Replace(".", @"\");
                    mf.createDirectory(projectName + @"\" + path);
                }
                else if (result == -1)
                {
                    MessageBox.Show("The Namespace is duplicated.");
                    return;
                }
                else
                {
                    MessageBox.Show("Creating new Namespace failed.");
                    return;
                }
            }
            else if (categoryCombo.SelectedItem.ToString() == "Class" && workCombo.SelectedItem.ToString() == "Create")
            {
                result = sql.insertClass(projectName, namespaceTree.getPath(), nameText.Text);
                if (result == 0)
                {
                    path = namespaceTree.getPath().Replace(".", @"\");
                    int    point = namespaceTree.getPath().LastIndexOf(".");
                    string curDir;
                    if (point != -1)
                    {
                        curDir = namespaceTree.getPath().Substring(point + 1);
                    }
                    else
                    {
                        curDir = namespaceTree.getPath();
                    }
                    mf.createFile(projectName + @"\" + path, curDir, nameText.Text);
                    classTree = new SetClassTreeView(classTreeView, fileName, projectName, namespaceTree.getPath());
                }
                else if (result == -1)
                {
                    MessageBox.Show("The Class is duplicated.");
                    return;
                }
                else
                {
                    MessageBox.Show("Creating new Class failed.");
                    return;
                }
            }
            else if (categoryCombo.SelectedItem.ToString() == "Field" && workCombo.SelectedItem.ToString() == "Create")
            {
                if (classTree.getClassName() != null)
                {
                    lastClassName = classTree.getClassName();
                }
                string type = null;
                if (typeCombo.SelectedItem == null)
                {
                    MessageBox.Show("Select a field type for this work.");
                    return;
                }
                else
                {
                    type = typeCombo.SelectedItem.ToString();
                }
                result = sql.insertField(projectName, namespaceTree.getPath(), lastClassName, nameText.Text, type);
                if (result == 0)
                {
                    path = namespaceTree.getPath().Replace(".", @"\");
                    int    point = namespaceTree.getPath().LastIndexOf(".");
                    string curDir;
                    if (point != -1)
                    {
                        curDir = namespaceTree.getPath().Substring(point + 1);
                    }
                    else
                    {
                        curDir = namespaceTree.getPath();
                    }
                    mf.addField(projectName + @"\" + path, lastClassName, nameText.Text, type);
                    classTree = new SetClassTreeView(classTreeView, fileName, projectName, namespaceTree.getPath());
                    classTree.expandNode(lastClassName);
                }
                else if (result == -1)
                {
                    MessageBox.Show("The Field is duplicated.");
                    return;
                }
                else
                {
                    MessageBox.Show("Creating new Field failed.");
                    return;
                }
            }
            else if (categoryCombo.SelectedItem.ToString() == "Namespace" && workCombo.SelectedItem.ToString() == "Delete")
            {
                WarningForm warningForm = new WarningForm();
                warningForm.ShowDialog();
                if (!warningForm.getCheckOK())
                {
                    return;
                }
                result = sql.deleteNamespace(projectName, nameText.Text);
                if (result == 0)
                {
                    namespaceTree = new SetNamespaceTreeView(namespaceTreeView, fileName, projectName);
                    namespaceTree.expandNode(nameText.Text);
                    path = nameText.Text;
                    path = path.Replace(".", @"\");
                    mf.deleteDirectory(projectName + @"\" + path);
                }
                else if (result == -1)
                {
                    MessageBox.Show("The Namespace dose not exist.");
                    return;
                }
                else
                {
                    MessageBox.Show("Deleting the Namespace failed.");
                    return;
                }
            }
            else if (categoryCombo.SelectedItem.ToString() == "Class" && workCombo.SelectedItem.ToString() == "Delete")
            {
                result = sql.deleteClass(projectName, workAtText.Text, nameText.Text);
                if (result == 0)
                {
                    classTree = new SetClassTreeView(classTreeView, fileName, projectName, namespaceTree.getPath());
                    path      = namespaceTree.getPath().Replace(".", @"\");
                    mf.deleteFile(projectName + @"\" + path, nameText.Text);
                }
                else if (result == -1)
                {
                    MessageBox.Show("The Class dose not exist.");
                    return;
                }
                else
                {
                    MessageBox.Show("Deleting the Class failed.");
                    return;
                }
            }
            else if (categoryCombo.SelectedItem.ToString() == "Field" && workCombo.SelectedItem.ToString() == "Delete")
            {
                if (classTree.getClassName() != null)
                {
                    lastClassName = classTree.getClassName();
                }
                result = sql.deleteField(projectName, namespaceTree.getPath(), lastClassName, nameText.Text);
                if (result == 0)
                {
                    path = namespaceTree.getPath().Replace(".", @"\");
                    int    point = namespaceTree.getPath().LastIndexOf(".");
                    string curDir;
                    if (point != -1)
                    {
                        curDir = namespaceTree.getPath().Substring(point + 1);
                    }
                    else
                    {
                        curDir = namespaceTree.getPath();
                    }
                    mf.deleteField(projectName + @"\" + path, lastClassName, nameText.Text);
                    classTree = new SetClassTreeView(classTreeView, fileName, projectName, namespaceTree.getPath());
                    classTree.expandNode(lastClassName);
                }
                else if (result == -1)
                {
                    MessageBox.Show("The Field dose not exist.");
                    return;
                }
                else
                {
                    MessageBox.Show("Deleting the Field failed.");
                    return;
                }
            }
            else if (categoryCombo.SelectedItem.ToString() == "Namespace" && workCombo.SelectedItem.ToString() == "Modify")
            {
                if (namespaceTree.getPath() == null)
                {
                    MessageBox.Show("Click a namespace in View for this work.");
                    return;
                }
                else if (namespaceTree.getPath() == nameText.Text)
                {
                    MessageBox.Show("Input changed name in Name Textbox for this work.");
                    return;
                }
                else if (nameText.Text.LastIndexOf(".") != -1)
                {
                    int    point = nameText.Text.LastIndexOf(".");
                    string temp  = nameText.Text.Substring(0, point);
                    if (namespaceTree.getParentPath() == null || namespaceTree.getParentPath() != temp)
                    {
                        MessageBox.Show("Invalid namespace. Try again appropriately.");
                        return;
                    }
                }
                else if (namespaceTree.getPath().LastIndexOf(".") != -1)
                {
                    MessageBox.Show("Invalid namespace. Try again appropriately.");
                    return;
                }
                result = sql.changeNamespace(projectName, namespaceTree.getPath(), nameText.Text);
                if (result == 0)
                {
                    string oldPath = namespaceTree.getPath().Replace(".", @"\");
                    string newPath = nameText.Text.Replace(".", @"\");
                    mf.modifyDirectory(projectName + @"\" + oldPath, projectName + @"\" + newPath);
                    namespaceTree = new SetNamespaceTreeView(namespaceTreeView, fileName, projectName);
                    namespaceTree.expandNode(nameText.Text);
                    nameText.Text = null;
                }
                else if (result == -1)
                {
                    MessageBox.Show("The Namespace is duplicated.");
                    return;
                }
                else
                {
                    MessageBox.Show("Changing the Namespace failed.");
                    return;
                }
            }
            else if (categoryCombo.SelectedItem.ToString() == "Class" && workCombo.SelectedItem.ToString() == "Modify")
            {
                if (classTree.getClassName() == null)
                {
                    MessageBox.Show("Click a class in View for this work.");
                    return;
                }
                else if (classTree.getClassName() == nameText.Text)
                {
                    MessageBox.Show("Input changed name in Name Textbox for this work.");
                    return;
                }
                result = sql.changeClass(projectName, workAtText.Text, classTree.getClassName(), nameText.Text);
                if (result == 0)
                {
                    path = workAtText.Text.Replace(".", @"\");
                    mf.modifyFile(projectName + @"\" + path, classTree.getClassName(), nameText.Text);
                    classTree     = new SetClassTreeView(classTreeView, fileName, projectName, namespaceTree.getPath());
                    nameText.Text = null;
                }
                else if (result == -1)
                {
                    MessageBox.Show("The Class is duplicated.");
                    return;
                }
                else
                {
                    MessageBox.Show("Changing the Class failed.");
                    return;
                }
            }
            else if (categoryCombo.SelectedItem.ToString() == "Field" && workCombo.SelectedItem.ToString() == "Modify")
            {
                if (classTree.getClassName() != null)
                {
                    lastClassName = classTree.getClassName();
                }
                if (classTree.getFieldName() == null)
                {
                    MessageBox.Show("Click a Field in View for this work.");
                    return;
                }
                else if (typeCombo.SelectedItem == null)
                {
                    MessageBox.Show("Select a field type in Type for this work.");
                    return;
                }
                result = sql.changeField(projectName, namespaceTree.getPath(), classTree.getClassName(), classTree.getFieldName(), nameText.Text, typeCombo.SelectedItem.ToString());
                if (result == 0)
                {
                    path = namespaceTree.getPath().Replace(".", @"\");
                    int    point = namespaceTree.getPath().LastIndexOf(".");
                    string curDir;
                    if (point != -1)
                    {
                        curDir = namespaceTree.getPath().Substring(point + 1);
                    }
                    else
                    {
                        curDir = namespaceTree.getPath();
                    }
                    mf.modifyField(projectName + @"\" + path, classTree.getClassName(), classTree.getFieldName(), nameText.Text, typeCombo.SelectedItem.ToString());
                    classTree = new SetClassTreeView(classTreeView, fileName, projectName, namespaceTree.getPath());
                    classTree.expandNode(lastClassName);
                    nameText.Text = null;
                }
                else if (result == -1)
                {
                    MessageBox.Show("The Field is duplicated.");
                    return;
                }
                else if (result == -3)
                {
                    MessageBox.Show("Input changed value.");
                    return;
                }
                else
                {
                    MessageBox.Show("Changing the Field failed.");
                    return;
                }
            }
            nameText.Focus();
        }