private void BtnGetResultsClick(object sender, EventArgs e)
        {
            try {
                List<string> suppliedTEs = GetSuppliedTEs(txtInputTes.Text.Trim());
                DataSet set = new DataSet("TE Collection");
                Sybase.Data.AseClient.AseConnection conn = new Sybase.Data.AseClient.AseConnection(connectionString);
                try {
                    conn.Open();
                    for (int i = 0; i < suppliedTEs.Count; i++) {
                        set.Tables.Add(GetTestDataTableFromDB(suppliedTEs[i],conn));
                    }
                    // work with set now
                    DataTable resultTable = set.Tables[0].Clone();
                    resultTable.Rows.Clear();
                    DataTable firstTable = set.Tables[0];
                    if ((firstTable.Rows != null)) {
                        //executionCtx,closestCPUTENumber,closestCPUValue,averageCPU
                        dgvResults.Columns.Add("executionCtx","Execution Context");
                        DataGridViewComboBoxColumn closestTEColumn = new DataGridViewComboBoxColumn();
                        closestTEColumn.Name = "ClosestTe";
                        closestTEColumn.HeaderText = "Closest TE";
                        closestTEColumn.DataSource = suppliedTEs.ToArray();
                        dgvResults.Columns.Add(closestTEColumn);
                        //   dgvResults.Columns.Add("closestCPUTENumber","Closest TE");
                        dgvResults.Columns.Add("closestCPUValue","Closest CPU Value");
                        dgvResults.Columns.Add("averageCPU","Average CPU");

                        foreach (DataRow row in firstTable.Rows) {
                            //resultTable.Rows.Add(GetAverageCPUFromRowsAndClosestTE(row["EXECUTION_TYPE"].ToString(),set));
                            dgvResults.Rows.Add(GetAverageCPUFromRowsAndClosestTE(row["EXECUTION_TYPE"].ToString(),set));
                        }
                    }
                } catch (Exception ex) {
                    CommonUtils.ShowError(ex.Message,ex);
                } finally {
                    conn.Close();
                }
                btnGetResults.Enabled = false;
            } catch (Exception ex) {
                CommonUtils.ShowError(ex.Message,ex);
            }
        }
 private void FillLocalUDTTable(DataTable gridValues)
 {
     Sybase.Data.AseClient.AseConnection conn = new Sybase.Data.AseClient.AseConnection(connectionString);
     PAC_TimingObject timingObject = new PAC_TimingObject();
     string maxLogicalTeNumber =  "PAR.TE.";
     try {
         conn.Open();
         DataTable table = new DataTable("TempTable");
         foreach (DataRow row in gridValues.Rows) {
             string selectedTe = row["closestCPUTENumber"].ToString();
             string executionContext = row["executionCtx"].ToString();
             using (Sybase.Data.AseClient.AseDataAdapter adapter = new Sybase.Data.AseClient.AseDataAdapter("Select * from QA_PAC_TIMING where TE_REF='"+selectedTe+"' and EXECUTION_TYPE='"+executionContext+"'" ,conn)) {
                 int rowsNumber =   adapter.Fill(table);
                 if (rowsNumber >1) {
                     rowsNumber = 0;
                 }
             }
         }
         Sybase.Data.AseClient.AseCommand commandMaxTE = new Sybase.Data.AseClient.AseCommand("select LOGICAL_TE from QA_PAC_REFERENCES_INT where ID in (Select max(ID) from QA_PAC_REFERENCES_INT)",conn);
         object returnedValue = commandMaxTE.ExecuteScalar();
         if (returnedValue !=null) {
             string[] teValueSplit = returnedValue.ToString().Split(new char[] {'.'},StringSplitOptions.RemoveEmptyEntries);
             Decimal teNumber = Convert.ToDecimal(teValueSplit[2]);
             teNumber = teNumber +1;
             maxLogicalTeNumber = maxLogicalTeNumber+teNumber.ToString("0000000");
         } else {
             maxLogicalTeNumber= maxLogicalTeNumber+"0000000";
         }
         DataTable table2 = table.Copy();
         table2.Columns.Add("SELECTED_TE");
         table2.Columns.Add("TE_GROUP");
         table2.Columns.Add("LOGICAL_TE");
         foreach (DataRow row in table2.Rows) {
             row["SELECTED_TE"]= row["TE_REF"].ToString();
             row["TE_GROUP"] = txtInputTes.Text.Trim();
             row["LOGICAL_TE"] = maxLogicalTeNumber;
         }
         dgvIntermediate.DataSource = table2;
     } catch (Exception ex) {
         CommonUtils.ShowError(ex.Message,ex);
     } finally {
         conn.Close();
     }
 }
 private void BtnInsertToPacClick(object sender, EventArgs e)
 {
     Sybase.Data.AseClient.AseConnection conn = new Sybase.Data.AseClient.AseConnection(connectionString);
     Sybase.Data.AseClient.AseTransaction transaction= null;
     try {
         conn.Open();
         transaction = conn.BeginTransaction();
         InsertPacReferences(ref conn, transaction);
         transaction.Commit();
         CommonUtils.ShowInformation("Insert into QA_PAC_REFERENCES_INT is complete, logical TE is ["+txtTELogical.Text+"]",false);
     } catch (Exception ex) {
         if (transaction != null) {
             transaction.Rollback();
         }
         CommonUtils.ShowError(ex.Message,ex);
     } finally {
         conn.Close();
     }
 }