public static string SaveAccount(string sMode, string sAccountID, string sAccountName, string sAccountNumber, string sProvider, string sLoginID, string sLoginPassword, string sLoginPasswordConfirm, string sIsDefault, string sAutoManageSecurity) { // for logging string sOriginalName = ""; dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); string sSql = ""; string sErr = ""; //if we are editing get the original values if (sMode == "edit") { } try { dataAccess.acTransaction oTrans = new dataAccess.acTransaction(ref sErr); // update the user fields. if (sMode == "edit") { sSql = "select account_name from cloud_account " + "where account_id = '" + sAccountID + "'"; if (!dc.sqlGetSingleString(ref sOriginalName, sSql, ref sErr)) throw new Exception("Error getting original account name:" + sErr); // only update the passwword if it has changed string sNewPassword = ""; if (sLoginPassword != "($%#d@x!&") { sNewPassword = "******" + dc.EnCrypt(sLoginPassword) + "'"; } sSql = "update cloud_account set" + " account_name = '" + sAccountName + "'," + " account_number = '" + sAccountNumber + "'," + " provider = '" + sProvider + "'," + " is_default = '" + sIsDefault + "'," + " auto_manage_security = '" + sAutoManageSecurity + "'," + " login_id = '" + sLoginID + "'" + sNewPassword + " where account_id = '" + sAccountID + "'"; oTrans.Command.CommandText = sSql; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception("Error updating account: " + sErr); ui.WriteObjectChangeLog(Globals.acObjectTypes.CloudAccount, sAccountID, sAccountName, sOriginalName, sAccountName);} else { //now, for some reason we were having issues with the initial startup of apache //not able to perform the very first database hit. //this line serves as an inital db hit, but we aren't trapping it or showing the error dc.TestDBConnection(ref sErr); //if there are no rows yet, make this one the default even if the box isn't checked. if (sIsDefault == "0") { int iExists = -1; sSql = "select count(*) as cnt from cloud_account"; if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { System.Threading.Thread.Sleep(300); if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { System.Threading.Thread.Sleep(300); if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) throw new Exception("Unable to count Cloud Accounts: " + sErr); } } if (iExists == 0) sIsDefault = "1"; } sAccountID = ui.NewGUID(); sSql = "insert into cloud_account (account_id, account_name, account_number, provider, is_default, login_id, login_password, auto_manage_security)" + " values ('" + sAccountID + "'," + "'" + sAccountName + "'," + "'" + sAccountNumber + "'," + "'" + sProvider + "'," + "'" + sIsDefault + "'," + "'" + sLoginID + "'," + "'" + dc.EnCrypt(sLoginPassword) + "'," + "'" + sAutoManageSecurity + "')"; oTrans.Command.CommandText = sSql; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception("Error creating account: " + sErr); ui.WriteObjectAddLog(Globals.acObjectTypes.CloudAccount, sAccountID, sAccountName, "Account Created"); } //if "default" was selected, unset all the others if (dc.IsTrue(sIsDefault)) { oTrans.Command.CommandText = "update cloud_account set is_default = 0 where account_id <> '" + sAccountID + "'"; if (!oTrans.ExecUpdate(ref sErr)) throw new Exception("Error updating defaults: " + sErr); } oTrans.Commit(); //refresh the cloud account list in the session if (!ui.PutCloudAccountsInSession(ref sErr)) throw new Exception("Error refreshing accounts in session: " + sErr); } catch (Exception ex) { throw new Exception("Error: General Exception: " + ex.Message); } // no errors to here, so return an empty string return "{'account_id':'" + sAccountID + "', 'account_name':'" + sAccountName + "', 'provider':'" + sProvider + "'}"; }
public static string SaveAccount(string sMode, string sAccountID, string sAccountName, string sAccountNumber, string sProvider, string sLoginID, string sLoginPassword, string sLoginPasswordConfirm, string sIsDefault, string sAutoManageSecurity) { // for logging string sOriginalName = ""; dataAccess dc = new dataAccess(); acUI.acUI ui = new acUI.acUI(); string sSql = ""; string sErr = ""; //if we are editing get the original values if (sMode == "edit") { } try { dataAccess.acTransaction oTrans = new dataAccess.acTransaction(ref sErr); // update the user fields. if (sMode == "edit") { sSql = "select account_name from cloud_account " + "where account_id = '" + sAccountID + "'"; if (!dc.sqlGetSingleString(ref sOriginalName, sSql, ref sErr)) { throw new Exception("Error getting original account name:" + sErr); } // only update the passwword if it has changed string sNewPassword = ""; if (sLoginPassword != "($%#d@x!&") { sNewPassword = "******" + dc.EnCrypt(sLoginPassword) + "'"; } sSql = "update cloud_account set" + " account_name = '" + sAccountName + "'," + " account_number = '" + sAccountNumber + "'," + " provider = '" + sProvider + "'," + " is_default = '" + sIsDefault + "'," + " auto_manage_security = '" + sAutoManageSecurity + "'," + " login_id = '" + sLoginID + "'" + sNewPassword + " where account_id = '" + sAccountID + "'"; oTrans.Command.CommandText = sSql; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception("Error updating account: " + sErr); } ui.WriteObjectChangeLog(Globals.acObjectTypes.CloudAccount, sAccountID, sAccountName, sOriginalName, sAccountName); } else { //now, for some reason we were having issues with the initial startup of apache //not able to perform the very first database hit. //this line serves as an inital db hit, but we aren't trapping it or showing the error dc.TestDBConnection(ref sErr); //if there are no rows yet, make this one the default even if the box isn't checked. if (sIsDefault == "0") { int iExists = -1; sSql = "select count(*) as cnt from cloud_account"; if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { System.Threading.Thread.Sleep(300); if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { System.Threading.Thread.Sleep(300); if (!dc.sqlGetSingleInteger(ref iExists, sSql, ref sErr)) { throw new Exception("Unable to count Cloud Accounts: " + sErr); } } } if (iExists == 0) { sIsDefault = "1"; } } sAccountID = ui.NewGUID(); sSql = "insert into cloud_account (account_id, account_name, account_number, provider, is_default, login_id, login_password, auto_manage_security)" + " values ('" + sAccountID + "'," + "'" + sAccountName + "'," + "'" + sAccountNumber + "'," + "'" + sProvider + "'," + "'" + sIsDefault + "'," + "'" + sLoginID + "'," + "'" + dc.EnCrypt(sLoginPassword) + "'," + "'" + sAutoManageSecurity + "')"; oTrans.Command.CommandText = sSql; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception("Error creating account: " + sErr); } ui.WriteObjectAddLog(Globals.acObjectTypes.CloudAccount, sAccountID, sAccountName, "Account Created"); } //if "default" was selected, unset all the others if (dc.IsTrue(sIsDefault)) { oTrans.Command.CommandText = "update cloud_account set is_default = 0 where account_id <> '" + sAccountID + "'"; if (!oTrans.ExecUpdate(ref sErr)) { throw new Exception("Error updating defaults: " + sErr); } } oTrans.Commit(); //refresh the cloud account list in the session if (!ui.PutCloudAccountsInSession(ref sErr)) { throw new Exception("Error refreshing accounts in session: " + sErr); } } catch (Exception ex) { throw new Exception("Error: General Exception: " + ex.Message); } // no errors to here, so return an empty string return("{'account_id':'" + sAccountID + "', 'account_name':'" + sAccountName + "', 'provider':'" + sProvider + "'}"); }