0

If i have set of business processes like that :

  • Reward
  • Vacation
  • Course
  • Overtime

And every process has an Insert Method Like this :

 public string InsertReward()
        {
            using (IfxConnection con = new IfxConnection(ConfigurationManager.ConnectionStrings["rr35"].ToString()))
            {
                int affectedRow = -1;
                int req_serial = 0;
                    req_serial = GetMaxSerial(DateTime.Now.Year);
                    StringBuilder cmdTxt = new StringBuilder();
                    cmdTxt.Append(" INSERT INTO RewardProcess(gen_year,gen_ser,bonus_type,bonus_date,bonus_desc,main_code,year,emp_num,active_ser) VALUES (?,?,?,?,?,?,?,?,? ) ");
                    using (var myIfxCmd = new IfxCommand(cmdTxt.ToString(), con))
                    {
                        myIfxCmd.CommandType = CommandType.Text;
                        myIfxCmd.Parameters.Add("gen_year", IfxType.Integer);
                        myIfxCmd.Parameters.Add("gen_ser", IfxType.Integer);
                        myIfxCmd.Parameters.Add("bonus_type", IfxType.SmallInt);
                        myIfxCmd.Parameters.Add("bonus_date", IfxType.Date);
                        myIfxCmd.Parameters.Add("bonus_desc", IfxType.NVarChar);
                        myIfxCmd.Parameters.Add("main_code", IfxType.Integer);
                        myIfxCmd.Parameters.Add("year", IfxType.Integer);
                        myIfxCmd.Parameters.Add("emp_num", IfxType.Integer);
                        myIfxCmd.Parameters.Add("active_ser", IfxType.SmallInt);

                        if (con.State == ConnectionState.Closed)
                        {
                            con.Open();
                        }

                        myIfxCmd.Parameters[0].Value = ((object)Req_year) ?? DBNull.Value;
                        myIfxCmd.Parameters[1].Value = ((object)req_serial) ?? DBNull.Value;
                        myIfxCmd.Parameters[2].Value = ((object)Bonus_type) ?? DBNull.Value;
                        myIfxCmd.Parameters[3].Value = ((object)Bonus_date) ?? DBNull.Value;
                        myIfxCmd.Parameters[4].Value = ((object)Bonus_desc) ?? DBNull.Value;
                        myIfxCmd.Parameters[5].Value = ((object)Main_code) ?? DBNull.Value;
                        myIfxCmd.Parameters[6].Value = ((object)Year) ?? DBNull.Value;
                        myIfxCmd.Parameters[7].Value = ((object)Emp_num) ?? DBNull.Value;
                        myIfxCmd.Parameters[8].Value = ((object)Active_ser) ?? DBNull.Value;
                        affectedRow = myIfxCmd.ExecuteNonQuery();
                    }
                    con.Close();
                    con.Dispose();
                    if (affectedRow > 0)
                    {
                        return DateTime.Now.Year + "," + req_serial;
                    }
                    else if (affectedRow == 0)
                    {
                        return string.Empty;
                    }
                    else
                    {
                        return affectedRow.ToString();
                    }
            }
        }

And After the business process insertion ,i insert transaction with the process ID .

Now I want to create a general method(for all Processes) , this method will check the process ID and call its insertion method and after that call the second method concerning the transaction method . i want all this in one transaction using ambient transaction

Is there something in .net allow to call the method knowing its signature as a string?

Void RootMethod(int processId)
{
   using(TransactionScope scope = new TransactionScope())
     {
         //1-Detect the signature of the insertion method by process id then call it by passing the suitable filled object 
         //2-call transaction method
      } 
}
Anyname Donotcare
  • 11,113
  • 66
  • 219
  • 392
  • 1
    juste use Reflection http://stackoverflow.com/questions/540066/calling-a-function-from-a-string-in-c-sharp. Although I would go with just an "Insert()" method and some polymorphism – Mickael V. Feb 01 '15 at 12:32

1 Answers1

0

Hi I would suggest a compile time approach: generate code for a registrar Indexing relevant methods( you could use CodeDom with a marking attribute for this mechanism) by their signature string.

Roman Ambinder
  • 369
  • 3
  • 7