Advertisement
Advertisement
| 09.17.2008 at 01:54AM PDT, ID: 23737847 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: |
/// <summary>
/// Return an account ID based on the ordernumber and telephone;
/// If no account already exists then generate a new account id and return its number.
/// </summary>
/// <param name="orderNumber"></param>
/// <param name="telephoneNumber"></param>
/// <returns></returns>
public int GetAccountId(string orderNumber, string telephoneNumber)
{
#region Instrumentation
if (log.IsInfoEnabled)
{
log.InfoFormat("{0}", MethodInfo.GetCurrentMethod().Name);
}
#endregion
// Get the id of the account based on the order number and tel, if no id then generate a new account
const string query = @"
BEGIN
DECLARE temp_id INTEGER;
SET temp_id = (SELECT ID FROM Account WHERE OrderNumber=@OrderNumber AND Telephone=@Telephone LIMIT 1);
IF temp_id = 0 THEN
BEGIN
INSERT INTO Account (OrderNumber,Telephone) VALUES (@OrderNumber,@Telephone);
SELECT last_insert_id();
END;
ELSE
BEGIN
SELECT temp_id;
END;
END IF;
END
";
MySqlDataAdapter msda = null;
try
{
msda = new MySqlDataAdapter(query, connectionString);
msda.SelectCommand.CommandType = CommandType.Text;
msda.SelectCommand.Parameters.AddWithValue("@OrderNumber", orderNumber);
msda.SelectCommand.Parameters.AddWithValue("@Telephone", orderNumber);
DataTable dt = null;
try
{
dt = new DataTable();
msda.Fill(dt);
if (dt.Rows.Count != 0)
{
dt.Locale = CultureInfo.InvariantCulture;
return Convert.ToInt32(dt.Rows[0][0]);
}
else
{
return 0;
}
}
catch (Exception ex)
{
dt.Dispose();
throw ex;
}
}
finally
{
if (msda != null) msda.Dispose();
}
}
|