> protected procedure SetPass > lparameters tnSiteNo, tcWhichKey, tcPrefix, tnPassNo, tcPassNo, tcDptCatItm, tnParentNo, tcPassTable > local lcKey, lcRetVal, lcSQLReturn, lnValprnttyp > > if empty(tcPassNo) > tcPassNo = alltrim(str(tnPassNo, 16, 0)) > endif > > with this > .write_log('Entering method...', program(), '1') > > if len(tcPrefix) = 0 && default prefix > tcPrefix = ' ' > endif > > && STEP 1 - Look in the prefix table to find out which tables to open > lcSQLReturn = .mysqlexec("select * from dbo.prefix where prefix = "+.VFP2SQL(tcPrefix), 'prefix', program(), .t.) > if !lcSQLReturn == 'OK' > lcRetVal = '400-'+lcSQLReturn > .write_log(lcRetVal, program(), 'E') > .write_log('Returning: '+lcRetVal, program(), '2') > return lcRetVal && calling prog does NOT expect .RetValToSTR() > endif > if (reccount('prefix') = 0 or eof('prefix')) or !prefix.prefix == left(tcPrefix, 1) > if upper(alltrim(tcWhichKey)) = 'PASS_NO' and tcPrefix = ' ' && FP# 7524 JT - If client does not have blank prefix, assume gst_pass table > .cPassTable = 'GST_PASS' && store for other procs to use > .cInfoTable = 'GUESTS' && where are name and e_message if they exist? > .cWhichKey = tcWhichKey > else > lcRetVal = '300-No Table Associated With "' + tcPrefix + '" In The PREFIX Table' > .write_log(lcRetVal, program(), 'E') > .write_log('Returning: '+lcRetVal, program(), '2') > return lcRetVal > endif > else > && STEP 2 - Save those table names to properties of the object for use by this method and calling methods > .cPassTable = alltrim(prefix.pass_table) && store for other procs to use > .cInfoTable = alltrim(prefix.info_table) && where are name and e_message if they exist? > if empty(.cInfoTable) > .cInfoTable = iif(lower(.cPassTable) = "access", "access", "guests") > endif > if empty(tcWhichKey) && retrieve from the prefix table... > .cWhichKey = prefix.whichkey > else > .cWhichKey = tcWhichKey > endif > if empty(.cWhichKey) && can't come up with anything? > .cWhichKey = 'pass_no' > endif > if vartype(tcPassTable) = 'C' and len(tcPassTable) > 3 > .cPassTable = tcPassTable > endif > endif > .cWhichKey = upper(alltrim(.cWhichKey)) > > if empty(trim(.cPassTable)) > lcRetVal = '300-No Table Associated With "' + tcPrefix + '" In The PREFIX Table' > .write_log(lcRetVal, program(), 'E') > .write_log('Returning: '+lcRetVal, program(), '2') > return lcRetVal &&calling prog does NOT expect .RetValToSTR() > endif > > && STEP 3 - Open the table containing the pass record > lcSQL = textmerge("SELECT * FROM <<This.cPassTable>> WHERE <<This.cWhichKey>> = ") + ; > .VFP2SQL(iif(.cWhichKey = 'SWIPE_NO', tcPassNo, tnPassNo)) > lcSQLReturn = .mysqlexec(lcSQL, .cPassTable, program(), .t.) > if !lcSQLReturn == 'OK' > lcRetVal = '400-' + lcSQLReturn > .write_log(lcRetVal, program(), 'E') > .write_log('Returning: ' + lcRetVal, program(), '2') > return lcRetVal && calling prog does NOT expect .RetValToSTR() > endif > > select (.cPassTable) > > && transform *sometimes* uses so many decimal places on doubles that it returns stars > if vartype(evaluate(.cWhichKey)) = 'C' > lcVal1 = alltrim(tcPassNo) > lcVal2 = alltrim(evaluate(.cWhichKey)) > else > lcVal1 = alltrim(str(tnPassNo,16,0)) > lcVal2 = alltrim(str(evaluate(.cWhichKey),16,0)) > endif > if not lcVal1 == lcVal2 > lcRetVal = '311-There Is No Record For ' + .cWhichKey + ' ' + ; > tcPrefix + lcVal1 + ' In Table ' + .cPassTable > .write_log(lcRetVal, program(), '3') > .write_log('Returning: '+lcRetVal, program(), '2') > return lcRetVal && calling prog does NOT expect .RetValToSTR() > endif > > .nOriginalPass = pass_no && valparent and val multiple passes can change > if type("guest_no") = 'N' && use type(), not vartype checking for fields existing! > .nOriginalGuest = guest_no > else > .nOriginalGuest = 0 > endif > > && STEP 4 - If this pass is associated with a guest, get that info ready and save > && that table name for future use (note: validate parent and cascading validations > && can use this info. It's also used to return the guest name) > if .nOriginalGuest <> 0 && !empty(.cInfoTable) && find parent information > lcSQLReturn = .mysqlexec("select guest_no, parent_no, first_name, last_name, e_message from " + .cInfoTable + ; > " where guest_no=" + .VFP2SQL(.nOriginalGuest), .cInfoTable, program(), .t.) > if !lcSQLReturn == 'OK' > lcRetVal = '400-' + lcSQLReturn > .write_log(lcRetVal, program(), 'E') > .write_log('Returning: ' + lcRetVal, program(), '2') > return lcRetVal && calling prog does NOT expect .RetValToSTR() > endif > endif > >>
>public class PassInfo : MiddlewareBase > { > /// <summary> > /// PassInfo Constructor > /// </summary> > /// <param name="databaseParam"></param> > public PassInfo(Database databaseParam) > { > database = databaseParam; > } > > public Decimal PassNo { get; set; } > public String PassTable { get; private set; } > public String WhichKey { get; private set; } > public String InfoTable { get; private set; } > > /// <summary> > /// Sets pass table and WhichKey based on the prefix > /// </summary> > /// <param name="prefix"></param> > /// <param name="messageText"></param> > /// <param name="statusCode"></param> > public Boolean SetPassTable(String prefix, ref String messageText, ref Int32 statusCode, String whichKey = "") > { > SqlCommand sqlCommand = new SqlCommand(); > sqlCommand.CommandText = @"select pass_table, whichkey, info_table > from dbo.prefix > where prefix=@prefix;"; > sqlCommand.CommandType = CommandType.Text; > sqlCommand.Parameters.Add("@prefix", SqlDbType.Char, 1).Value = prefix; > DataSet dsPrefix; > > if (database.ExecuteSqlCommand(sqlCommand, out dsPrefix, ref messageText, ref statusCode)) > { > foreach (DataRow row in dsPrefix.Tables[0].Rows) > { > PassTable = row["pass_table"].ToString().Trim(); > if (!String.IsNullOrWhiteSpace(whichKey)) > WhichKey = whichKey; > else > WhichKey = row["whichkey"].ToString().Trim(); > InfoTable = row["info_table"].ToString().Trim(); > } > if ((0 == dsPrefix.Tables[0].Rows.Count) || String.IsNullOrEmpty(PassTable)) > { > statusCode = 300; > messageText = "No Table Associated With " + prefix + " In The PREFIX Table"; > return false; > } > else > { > if (String.IsNullOrEmpty(WhichKey)) > WhichKey = "pass_no"; > > if (String.IsNullOrEmpty(InfoTable)) > { > if ("access" == PassTable.ToLower()) > InfoTable = "access"; > else > InfoTable = "guests"; > } > } > return true; > } > else > return false; > } > > /// <summary> > /// Constructs SQL Command for the passTable and WhichKey > /// </summary> > /// <param name="passNo"></param> > /// <param name="cPassNo"></param> > /// <param name="tcDCI"></param> > /// <returns></returns> > public SqlCommand GetPassSqlCommand(Decimal passNo, String cPassNo, String tcDCI = "") > { > SqlCommand sqlCommand = new SqlCommand(); > if ("swipe_no" == WhichKey.ToLower()) > sqlCommand.Parameters.Add("@value", SqlDbType.VarChar).Value = cPassNo; > else > sqlCommand.Parameters.Add("@value", SqlDbType.Decimal).Value = passNo; > sqlCommand.CommandType = CommandType.Text; > StringBuilder whereClause = new StringBuilder("where "); > whereClause.Append(WhichKey); > whereClause.Append("= @value"); > > if (!String.IsNullOrEmpty(tcDCI)) > { > tcDCI = tcDCI.PadRight(30); > String department = tcDCI.Substring(0, 10); > String category = tcDCI.Substring(10, 10); > String item = tcDCI.Substring(20, 10); > whereClause.Append(" and department = @department and category = @category and item = @item"); > sqlCommand.Parameters.Add("@department", SqlDbType.Char, 10).Value = department; > sqlCommand.Parameters.Add("@category", SqlDbType.Char, 10).Value = category; > sqlCommand.Parameters.Add("@item", SqlDbType.Char, 10).Value = item; > } > > sqlCommand.CommandText = String.Format("select *, '{0}' as passtable {1} from dbo.{0}{1} {2}", PassTable, Environment.NewLine, whereClause.ToString()); > return sqlCommand; > } > }>