public static void deleteProfileFromAccount(userAccount owningAccount, fundingProfile profileToDelete) { owningAccount.profiles.Remove(profileToDelete); //Database stuff database.sqlStatement deleteSql = new database.sqlStatement(); deleteSql.connectionString = database.getConnectString(); /* Delete the Child Cash Flows */ deleteSql.query = "DELETE FROM bmw_cash_flow " + "WHERE profile_id = @profile_id "; deleteSql.queryParameters.Add("@profile_id", profileToDelete.id); database.executeNonQueryOnDatabase(deleteSql); deleteSql.queryParameters.Clear(); /* Delete the Profile */ deleteSql.query = "DELETE FROM bmw_funding_profile " + "WHERE id = @id "; deleteSql.queryParameters.Add("@id", profileToDelete.id); database.executeNonQueryOnDatabase(deleteSql); }
/// <summary> /// Replaces an item in a list with a new item /// [This is the overload for fundingProfiles] /// </summary> /// <param name="parentList"></param> /// <param name="itemToReplace"></param> /// <param name="newItem"></param> public static void replaceItemInList(List <fundingProfile> parentList, fundingProfile itemToReplace, fundingProfile newItem) { int index = parentList.IndexOf(itemToReplace); if (index != -1) { parentList[index] = newItem; } }
private bool importCashFlowsIntoProfile(DataTable csvData, fundingProfile profileToRecieveFlows) { List <cashFlow> csvFlows = new List <cashFlow>(); foreach (DataRow row in csvData.Rows) { csvFlows.Add(new cashFlow(common.getNextCashFlowId(), row["flow_name"].ToString(), float.Parse(row["amount"].ToString()), DateTime.Parse(row["due_date"].ToString()), DateTime.Parse(row["transaction_date"].ToString()), common.getCashFlowTypeByName(row["flow_type"].ToString()))); } //Database stuff database.sqlStatement insertSql = new database.sqlStatement(); insertSql.connectionString = database.getConnectString(); insertSql.query = "INSERT INTO bmw_cash_flow " + "(profile_id,flow_name,flow_type,amount,transaction_date,due_date) " + "VALUES "; //+ //"(@id,@profile_id,@flow_name,@flow_type,@amount,@transaction_date,@due_date) "; List <string> values = new List <string>(); foreach (cashFlow flow in csvFlows) { values.Add("(@profile_id" + csvFlows.IndexOf(flow) + "," + "@flow_name" + csvFlows.IndexOf(flow) + "," + "@flow_type" + csvFlows.IndexOf(flow) + "," + "@amount" + csvFlows.IndexOf(flow) + "," + "@transaction_date" + csvFlows.IndexOf(flow) + "," + "@due_date" + csvFlows.IndexOf(flow) + ") "); //insertSql.queryParameters.Add("@id" + csvFlows.IndexOf(flow), flow.id); insertSql.queryParameters.Add("@profile_id" + csvFlows.IndexOf(flow), profileToRecieveFlows.id); insertSql.queryParameters.Add("@flow_name" + csvFlows.IndexOf(flow), flow.name); insertSql.queryParameters.Add("@flow_type" + csvFlows.IndexOf(flow), flow.flowType); insertSql.queryParameters.Add("@amount" + csvFlows.IndexOf(flow), flow.amount); insertSql.queryParameters.Add("@transaction_date" + csvFlows.IndexOf(flow), flow.flowDate); insertSql.queryParameters.Add("@due_date" + csvFlows.IndexOf(flow), flow.dueDate); } insertSql.query += string.Join(",", values); database.executeNonQueryOnDatabase(insertSql); profileToRecieveFlows.cashFlows.AddRange(csvFlows); return(true); }
public static void deleteCashFlowFromProfile(fundingProfile owningProfile, cashFlow flowToDelete) { owningProfile.cashFlows.Remove(flowToDelete); //Database stuff database.sqlStatement deleteSql = new database.sqlStatement(); deleteSql.connectionString = database.getConnectString(); deleteSql.query = "DELETE FROM bmw_cash_flow " + "WHERE id = @id "; deleteSql.queryParameters.Add("@id", flowToDelete.id); database.executeNonQueryOnDatabase(deleteSql); }
/// <summary> /// Checks if the given cash flow name already exists on the loaded profile /// </summary> /// <param name="cashFlowName"></param> /// <returns></returns> private bool isCashFlowNameDuplicate(fundingProfile owningProfile, string cashFlowName) { List <cashFlow> profileFlows = owningProfile.cashFlows; if (loadedFlow != null) { /* exclude the flow we're editing (if any) from the dupe check*/ return(profileFlows.Where(x => x.id != loadedFlow.id).Where(x => x.name.ToLower() == cashFlowName.ToLower()).Count() > 0); } else { return(profileFlows.Where(x => x.name.ToLower() == cashFlowName.ToLower()).Count() > 0); } }
private void renameSelectedProfileToolStripMenuItem_Click(object sender, EventArgs e) { if (getSelectedProfile() == null) { using (frmMessageBox messageBox = new frmMessageBox()) { common.setFormFontSize(messageBox, common.getMainForm().loadedFontSize); common.getMainForm().loadedTheme.themeForm(messageBox); messageBox.show("No Profile Selected.", "No Profile Selected", MessageBoxButtons.OK); } } else { using (frmInputBox inputBox = new frmInputBox()) { common.setFormFontSize(inputBox, common.getMainForm().loadedFontSize); common.getMainForm().loadedTheme.themeForm(inputBox); inputBox.Text = "Rename Profile: [" + getSelectedProfile().name + "]"; inputBox.lblMessage.Text = "Enter new profile name:"; inputBox.txtInput.Text = getSelectedProfile().name; inputBox.ShowDialog(); /* i.e. only process if the user said OK */ if (inputBox.DialogResult == DialogResult.OK) { if (!string.IsNullOrEmpty(inputBox.result) && !isRenameProfileNameDuplicate(this.loadedAccount.profiles, inputBox.result)) { //rename profile fundingProfile renamedProfile = new fundingProfile(getSelectedProfile().id, inputBox.result, getSelectedProfile().cashFlows); common.updateProfileOnAccount(common.getMainForm().loadedAccount, getSelectedProfile(), renamedProfile); common.getMainForm().refreshDataForAllMdiChildren(); } else { using (frmMessageBox messageBox = new frmMessageBox()) { common.setFormFontSize(messageBox, common.getMainForm().loadedFontSize); common.getMainForm().loadedTheme.themeForm(messageBox); messageBox.show("You cannot have more than one profile with the same name", "Duplicate Profile Name", MessageBoxButtons.OK); } } } } } }
public static void updateProfileOnAccount(userAccount owningAccount, fundingProfile oldProfile, fundingProfile updatedProfile) { replaceItemInList(owningAccount.profiles, oldProfile, updatedProfile); //Database stuff database.sqlStatement updateSql = new database.sqlStatement(); updateSql.connectionString = database.getConnectString(); updateSql.query = "UPDATE bmw_funding_profile " + "SET profile_name = @profile_name " + "WHERE id = @id "; updateSql.queryParameters.Add("@id", oldProfile.id); updateSql.queryParameters.Add("@profile_name", updatedProfile.name); database.executeNonQueryOnDatabase(updateSql); }
public static void addProfileToAccount(userAccount accountToAddProfile, fundingProfile profileToAdd) { accountToAddProfile.profiles.Add(profileToAdd); //Database stuff database.sqlStatement insertSql = new database.sqlStatement(); insertSql.connectionString = database.getConnectString(); insertSql.query = "INSERT INTO bmw_funding_profile " + "(id,account_id,profile_name) " + "VALUES " + "(@id, @account_id, @profile_name) "; insertSql.queryParameters.Add("@id", profileToAdd.id); insertSql.queryParameters.Add("@account_id", accountToAddProfile.id); insertSql.queryParameters.Add("@profile_name", profileToAdd.name); database.executeNonQueryOnDatabase(insertSql); }
public void testGetAccountCashFlows() { userAccount testAccount = new userAccount(); fundingProfile testProfile = new fundingProfile(); cashFlow testFlow = new cashFlow(); fundingProfile testProfile2 = new fundingProfile(); cashFlow testFlow2 = new cashFlow(); testFlow.name = "Test Flow 1"; testFlow2.name = "Test Flow 2"; testProfile.cashFlows.Add(testFlow); testProfile2.cashFlows.Add(testFlow2); testAccount.profiles.Add(testProfile); testAccount.profiles.Add(testProfile2); Assert.IsTrue(testAccount.getAccountCashFlows().Contains(testFlow)); Assert.IsTrue(testAccount.getAccountCashFlows().Contains(testFlow2)); }
public static void addCashFlowToProfile(fundingProfile profileToRecieveFlow, cashFlow flowToAdd) { profileToRecieveFlow.cashFlows.Add(flowToAdd); //Database stuff database.sqlStatement insertSql = new database.sqlStatement(); insertSql.connectionString = database.getConnectString(); insertSql.query = "INSERT INTO bmw_cash_flow " + "(id,profile_id,flow_name,flow_type,amount,transaction_date,due_date) " + "VALUES " + "(@id,@profile_id,@flow_name,@flow_type,@amount,@transaction_date,@due_date) "; insertSql.queryParameters.Add("@id", flowToAdd.id); insertSql.queryParameters.Add("@profile_id", profileToRecieveFlow.id); insertSql.queryParameters.Add("@flow_name", flowToAdd.name); insertSql.queryParameters.Add("@flow_type", flowToAdd.flowType); insertSql.queryParameters.Add("@amount", flowToAdd.amount); insertSql.queryParameters.Add("@transaction_date", flowToAdd.flowDate); insertSql.queryParameters.Add("@due_date", flowToAdd.dueDate); database.executeNonQueryOnDatabase(insertSql); }
public static void updateCashFlowOnAccount(fundingProfile owningProfile, cashFlow oldFlow, cashFlow updatedFlow) { replaceItemInList(owningProfile.cashFlows, oldFlow, updatedFlow); //Database stuff database.sqlStatement updateSql = new database.sqlStatement(); updateSql.connectionString = database.getConnectString(); updateSql.query = "UPDATE bmw_cash_flow " + "SET flow_name = @flow_name, " + "flow_type = @flow_type, " + "amount = @amount, " + "transaction_date = @transaction_date, " + "due_date = @due_date " + "WHERE id = @id "; updateSql.queryParameters.Add("@id", oldFlow.id); updateSql.queryParameters.Add("@flow_name", updatedFlow.name); updateSql.queryParameters.Add("@flow_type", updatedFlow.flowType); updateSql.queryParameters.Add("@amount", updatedFlow.amount); updateSql.queryParameters.Add("@transaction_date", updatedFlow.flowDate); updateSql.queryParameters.Add("@due_date", updatedFlow.dueDate); database.executeNonQueryOnDatabase(updateSql); }
public void loadProfileIntoForm(fundingProfile profileToLoad) { this.loadedProfile = profileToLoad; tsslFlowStatus.Text = "Loaded Profile: " + loadedProfile.name; }