Ejemplo n.º 1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            string aStorage     = "";                  // name of Storage
            string aProjectPath = "";
            string aPlaceName   = comboPlaces.Text;    // name of selected Place
            string aPlacePath   = "";
            string aProjectName = txtProjectName.Text; // project to which we have to save the map

            using (ProjectsDB _db = new ProjectsDB())
            {
                DataTable _dt = _db.ExecuteQuery("select * from PROJECTS where PROJECTNAME='" + aProjectName + "' and PLACENAME='" + aPlaceName + "'");
                if (_dt.Rows.Count > 0) // project with this name already exists
                {
                    lblProjectNameError.Text = MMUtils.GetString("createprojectdlg.projectexists.text");
                    return;
                }
            }

            // project name not entered
            if (aProjectName == "")
            {
                lblProjectNameError.Text = MMUtils.GetString("createprojectdlg.projectnameempty.text");
                return;
            }

            using (PlacesDB _db = new PlacesDB())
            {
                DataTable _dt = _db.ExecuteQuery("select * from PLACES where PLACENAME='" + aPlaceName + "'");
                aStorage   = _dt.Rows[0]["STORAGE"].ToString();
                aPlacePath = _dt.Rows[0]["PLACEPATH"].ToString();
            }

            aProjectPath = aPlacePath + "$$" + aProjectName;
            string _localPath = MMUtils.m_SynergyLocalPath + aPlaceName + "\\" + aProjectName;

            try
            {
                System.IO.Directory.CreateDirectory(_localPath);
                System.IO.Directory.CreateDirectory(aProjectPath); // in the Place
            }
            catch (Exception _e)                                   // TODO cause!!! read-only, etc...
            {
                MessageBox.Show(this, "Error " + _e.Message, "title", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.DialogResult = DialogResult.Cancel; // TODO
            }

            ProjectsDB.AddProjectToDB(aStorage, aPlaceName, aProjectName, aProjectPath, _localPath);

            this.DialogResult = DialogResult.OK;
        }