public StatusCode UpdateApplicationPayment(string userID, string applicationID, PaymentInfo paymentInfo)
        {
            StatusCode status = StatusCode.Fail;
            if (paymentInfo != null)
            {
                if (paymentInfo.PaymentType == PaymentType.VIP)
                {
                    applicationID = "VIP";
                    if (HasApplicationAccountInfo(userID, applicationID))
                    {
                        if (UpdatePurchaseInfo(userID, applicationID, paymentInfo))
                        {
                            status = StatusCode.Success;
                        }
                    }
                    else
                    {
                        AccountInfo vipAccountInfo = new AccountInfo();
                        vipAccountInfo.ApplicationID = applicationID;
                        vipAccountInfo.UserID = userID;
                        vipAccountInfo.AccountType = AccountType.VIP;
                        vipAccountInfo.PaymentInfo = paymentInfo;

                        status = AddAccountInfo(vipAccountInfo);
                    }

                }
                else
                {
                    if (HasApplicationAccountInfo(userID, applicationID))
                    {
                        if (UpdatePurchaseInfo(userID, applicationID, paymentInfo))
                        {
                            status = StatusCode.Success;
                        }
                    }
                    else
                    {
                        AccountInfo paidAccountInfo = new AccountInfo();
                        paidAccountInfo.ApplicationID = applicationID;
                        paidAccountInfo.UserID = userID;
                        paidAccountInfo.AccountType = AccountType.Paid;
                        paidAccountInfo.PaymentInfo = paymentInfo;

                        status = AddAccountInfo(paidAccountInfo);
                    }
                }
            }
            return status;
        }
        //tested
        public StatusCode AddAccountInfo(AccountInfo accountInfo)
        {
            StatusCode retStatus = StatusCode.Success;
            try
            {
                StringBuilder sql = new StringBuilder("INSERT INTO [tb_AccountInfo] ([ApplicationID],[UserID],[UserName],[AccountType],[Locked],"
                        + "[LockedDate],[LockCode],[ExpiryTime],[PaymentInfo]) VALUES(");
                SqlCommand sc = new SqlCommand();

                if (String.IsNullOrEmpty(accountInfo.ApplicationID))
                    sql.Append("null,");
                else
                    sql.Append("'" + accountInfo.ApplicationID + "',");

                if (String.IsNullOrEmpty(accountInfo.UserID))
                    sql.Append("null,");
                else
                    sql.Append("'" + accountInfo.UserID + "',");

                if (String.IsNullOrEmpty(accountInfo.UserName))
                    sql.Append("null,");
                else
                    sql.Append("'" + accountInfo.UserName + "',");

                sql.Append("@acctype,");
                sc.Parameters.AddWithValue("@acctype", accountInfo.AccountType.ToString());

                //Locked will not be null
                sql.Append("'" + accountInfo.Locked + "',");

                if (accountInfo.LockedDateSpecified && accountInfo.LockedDate != null)
                    sql.Append("'" + accountInfo.LockedDate + "',");
                else
                    sql.Append("null,");

                if (accountInfo.Locked && !String.IsNullOrEmpty(accountInfo.LockCode))
                    sql.Append("'" + accountInfo.LockCode + "',");
                else
                    sql.Append("null,");

                if (accountInfo.ExpiryTimeSpecified && accountInfo.ExpiryTime != null)
                    sql.Append("'" + accountInfo.ExpiryTime + "',");
                else
                    sql.Append("null,");

                if (accountInfo.PaymentInfo != null)
                {
                    //sql.Append( "'" + XMLToString(accountInfo.PaymentInfo) + "',";
                    sql.Append("@paymentinfo");
                    sc.Parameters.AddWithValue("@paymentinfo", XMLToString(accountInfo.PaymentInfo));
                }
                else
                    sql.Append("null");

                sql.Append(")");

                da.ExecuteNonQuery(sql.ToString(), sc);
            }
            catch (Exception ex)
            {
                retStatus = StatusCode.Fail;
            }
            return retStatus;
        }
        //tested
        public AccountInfo GetAccountInfo(string userID, string applicationID)
        {
            AccountInfo foundAccountInfo = null;

            if (userID != null && applicationID != null)
            {
                string sql = "select * from [tb_AccountInfo] where [UserID]=@userid and [ApplicationID]=@appid";
                SqlCommand sc = new SqlCommand(sql);
                sc.Parameters.AddWithValue("@userid", userID);
                sc.Parameters.AddWithValue("@appid", applicationID);
                DataTable dtinfo = da.GetDataTable(sql, sc);
                if (dtinfo != null && dtinfo.Rows != null && dtinfo.Rows.Count > 0)
                {
                    DataRowWrapper rowWrapper = new DataRowWrapper(dtinfo.Rows[0]);

                    foundAccountInfo = new AccountInfo();
                    foundAccountInfo.ApplicationID = applicationID;
                    foundAccountInfo.UserID = userID;

                    foundAccountInfo.UserName = rowWrapper.GetColumnValueAsString("UserName");
                    foundAccountInfo.AccountType = (AccountType)rowWrapper.GetEnumColumnValue("AccountType", typeof(AccountType));
                    foundAccountInfo.Locked = rowWrapper.GetColumnValueAsBool("Locked");
                    foundAccountInfo.LockedDate = dtinfo.Rows[0]["LockedDate"].ToString() != "" ? Convert.ToDateTime(dtinfo.Rows[0]["LockedDate"].ToString()) : Convert.ToDateTime("1900-01-01");
                    foundAccountInfo.LockedDateSpecified = (foundAccountInfo.LockedDate.ToString("yyyy-MM-dd") == "1900-01-01") ? false : true;
                    foundAccountInfo.LockCode = rowWrapper.GetColumnValueAsString("LockCode");
                    foundAccountInfo.ExpiryTime = dtinfo.Rows[0]["ExpiryTime"].ToString() != "" ? Convert.ToDateTime(dtinfo.Rows[0]["ExpiryTime"].ToString()) : Convert.ToDateTime("1900-01-01");
                    foundAccountInfo.ExpiryTimeSpecified = (foundAccountInfo.ExpiryTime.ToString("yyyy-MM-dd") == "1900-01-01") ? false : true;
                    foundAccountInfo.PaymentInfo = rowWrapper.GetTypedColumnValue("PaymentInfo", typeof(PaymentInfo)) as PaymentInfo;

                    foundAccountInfo.DeviceInfoList = rowWrapper.GetTypedColumnValue("DeviceInfos", typeof(DeviceInfoList)) as DeviceInfoList;
                }
            }

            return foundAccountInfo;
        }