/// <summary> /// Update an existing item in the Project List /// </summary> /// <param name="item"></param> /// <returns></returns> public static void Update(Project item) { Project toUpdate = AllProjects.Find(proj => proj.Id == item.Id); toUpdate = new Project() { ConnectionStringDestination = item.ConnectionStringDestination, ConnectionStringSource = item.ConnectionStringSource, Id = item.Id, Name = item.Name, Type = item.Type, WasLastUsed = item.WasLastUsed }; }
private void OpenProject() { if (listView1.SelectedItems.Count != 0) { Project item = new Project(); item.ConnectionStringDestination = projects[listView1.SelectedItems[0].Index].ConnectionStringDestination; item.ConnectionStringSource = projects[listView1.SelectedItems[0].Index].ConnectionStringSource; item.Id = projects[listView1.SelectedItems[0].Index].Id; item.Name = projects[listView1.SelectedItems[0].Index].Name; item.Type = projects[listView1.SelectedItems[0].Index].Type; if (OnSelect != null) OnSelect(item); } }
private void form_OnRename(Project itemSelected) { Project.Save(itemSelected); }
private void form_OnSelect(Project itemSelected) { try { if (itemSelected != null) { ActiveProject = itemSelected; mySqlConnectFront1.ConnectionString = itemSelected.ConnectionStringSource; mySqlConnectFront2.ConnectionString = itemSelected.ConnectionStringDestination; } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void form_OnRename(Project itemSelected) { try { Project.Save(itemSelected); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void form_OnDelete(Project itemSelected) { try { Project.Delete(itemSelected.Id); if (ActiveProject != null) { if (ActiveProject.Id == itemSelected.Id) { ActiveProject = null; mySqlConnectFront1.ConnectionString = ""; mySqlConnectFront2.ConnectionString = ""; } } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button1_Click_1(object sender, EventArgs e) { try { if (ActiveProject == null) { ActiveProject = new Project { ConnectionStringSource = mySqlConnectFront1.ConnectionString, ConnectionStringDestination = mySqlConnectFront2.ConnectionString, Name = String.Format("[{0}].[{1}] - [{2}].[{3}]", ((SqlServerConnectFront)mySqlConnectFront1).ServerName, mySqlConnectFront1.DatabaseName, ((SqlServerConnectFront)mySqlConnectFront2).ServerName, mySqlConnectFront2.DatabaseName), Type = Project.ProjectType.SQLServer }; } ActiveProject.Id = Project.Save(ActiveProject); } catch (Exception ex) { MessageBox.Show(this, ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static int Add(Project item) { int maxId = 0; Project.DoSqlSomething( "SELECT MAX(ProjectId) AS NewId FROM Project WHERE Internal = 0", reader => maxId = int.Parse(reader["NewId"].ToString()), "INSERT INTO Project (Name, ConnectionStringSource, ConnectionStringDestination, Options, Type, Internal) VALUES ('" + item.Name.Replace("'","''") + "','" + item.ConnectionStringSource + "','" + item.ConnectionStringDestination + "','" + item.Options + "'," + ((int) item.Type).ToString() + ",0)"); return maxId; }
private void btnNewProject_Click(object sender, EventArgs e) { mySqlConnectFront1.ConnectionString = ""; mySqlConnectFront2.ConnectionString = ""; ActiveProject = null; }
/// <summary> /// Add a Project to the list in the databse /// </summary> /// <param name="item"></param> /// <returns></returns> public static void Add(Project item) { AllProjects.Add(item); }
public static void SaveLastConfiguration(string ConnectionStringSource, string ConnectionStringDestination) { Project lastUsedProject = AllProjects.Find(proj => proj.ConnectionStringSource.ToLower() == ConnectionStringSource.ToLower() && proj.ConnectionStringDestination.ToLower() == ConnectionStringDestination.ToLower()); AllProjects.ForEach(proj => proj.WasLastUsed = false); if (lastUsedProject == null) { lastUsedProject = new Project() { ConnectionStringDestination = ConnectionStringDestination, ConnectionStringSource = ConnectionStringSource, Type = ProjectType.SQLServer, WasLastUsed = true }; lastUsedProject.Id = Project.AllProjects.Count + 1; Add(lastUsedProject); } else { lastUsedProject.WasLastUsed = true; lastUsedProject.ConnectionStringSource = ConnectionStringSource; lastUsedProject.ConnectionStringDestination = ConnectionStringDestination; Update(lastUsedProject); } //Serialize the changes back down to disk Serialize(); }
public static Project GetLastConfiguration() { Project item = null; Project.DoSqlSomething( "SELECT * FROM Project WHERE Internal = 1 ORDER BY Name", reader => item = new Project { Id = int.Parse(reader["ProjectId"].ToString()), ConnectionStringSource = reader["ConnectionStringSource"].ToString(), ConnectionStringDestination = reader["ConnectionStringDestination"].ToString(), Type = (ProjectType)(long)reader["Type"], //Options = (SqlOption) reader["Options"], Name = reader["Name"].ToString() }); return item; }
private static int Update(Project item) { Project.DoSqlSomething( "UPDATE Project SET Name = '" + item.Name.Replace("'","''") + "', ConnectionStringSource = '" + item.ConnectionStringSource + "', ConnectionStringDestination = '" + item.ConnectionStringDestination + "', Type = " + ((int)item.Type).ToString() + " WHERE ProjectId = " + item.Id.ToString(), null); return item.Id; }
private void form_OnDelete(Project itemSelected) { Project.Delete(itemSelected.Id); if (ActiveProject != null) { if (ActiveProject.Id == itemSelected.Id) { ActiveProject = null; mySqlConnectFront1.ConnectionString = ""; mySqlConnectFront2.ConnectionString = ""; } } }
/// <summary> /// Save an item, decide whether to insert or update. /// </summary> /// <param name="item"></param> /// <returns></returns> public static void Save(Project item) { Project projectToSave = AllProjects.Find(proj => proj.Id == item.Id); if (projectToSave == null) { item.Id = Project.AllProjects.Count + 1; Add(item); } else Update(projectToSave); Serialize(); }
private void form_OnSelect(Project itemSelected) { if (itemSelected != null) { ActiveProject = itemSelected; mySqlConnectFront1.ConnectionString = itemSelected.ConnectionStringSource; mySqlConnectFront2.ConnectionString = itemSelected.ConnectionStringDestination; } }
private void OpenProject() { try { if (listView1.SelectedItems.Count != 0) { Project item = new Project(); item.ConnectionStringDestination = projects[listView1.SelectedItems[0].Index].ConnectionStringDestination; item.ConnectionStringSource = projects[listView1.SelectedItems[0].Index].ConnectionStringSource; item.Id = projects[listView1.SelectedItems[0].Index].Id; item.Name = projects[listView1.SelectedItems[0].Index].Name; item.Options = projects[listView1.SelectedItems[0].Index].Options; item.Type = projects[listView1.SelectedItems[0].Index].Type; if (OnSelect != null) OnSelect(item); } } catch (Exception ex) { MessageBox.Show(this, ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnSaveProject_Click(object sender, EventArgs e) { if (ActiveProject == null) { ActiveProject = new Project { ConnectionStringSource = mySqlConnectFront1.ConnectionString, ConnectionStringDestination = mySqlConnectFront2.ConnectionString, Name = mySqlConnectFront1.DatabaseName + " - " + mySqlConnectFront2.DatabaseName, Type = Project.ProjectType.SQLServer }; } Project.Save(ActiveProject); }
public static int Save(Project item) { if (item.Id == 0) return Add(item); return Update(item); }