private void InsertPacReferences(ref Sybase.Data.AseClient.AseConnection conn, Sybase.Data.AseClient.AseTransaction transaction) { foreach (DataGridViewRow gridRow in dgvIntermediate.Rows) { string idInPacTiming = gridRow.Cells["ID"].Value.ToString(); string teLogical = gridRow.Cells["LOGICAL_TE"].Value.ToString(); string referenceType = gridRow.Cells["REFERENCE_TYPE"].Value.ToString().Replace("REACHED", "EXPECTED"); txtTELogical.Text = "TE Logical: "+teLogical; Sybase.Data.AseClient.AseCommand commandUpdateValuesInPacTiming = new Sybase.Data.AseClient.AseCommand(" UPDATE QA_PAC_TIMING " + " SET TE_REF='" + teLogical + "' " + " REFERENCE_TYPE='" + referenceType + "' " + " WHERE ID=" + idInPacTiming, conn,transaction); Sybase.Data.AseClient.AseCommand commandInsertToIntermediate = new Sybase.Data.AseClient.AseCommand(commandText, conn,transaction); Sybase.Data.AseClient.AseCommand commandSelectMaxIdFromInter = new Sybase.Data.AseClient.AseCommand("Select max(ID) from QA_PAC_REFERENCES_INT", conn,transaction); object maxIdInIntermediate = commandSelectMaxIdFromInter.ExecuteScalar(); if (string.IsNullOrEmpty(maxIdInIntermediate.ToString())) { maxIdInIntermediate = 1; } decimal maxIdIntermediate = Convert.ToDecimal(maxIdInIntermediate) + 1; PAC_TimingObject timingObject = new PAC_TimingObject(); string[] keyArray = new string[timingObject.paramtersWithValues.Keys.Count]; timingObject.paramtersWithValues.Keys.CopyTo(keyArray, 0); int counter = 0; commandInsertToIntermediate.Parameters.Add("@ID", maxIdIntermediate); string valuesInsertedToLog = string.Empty; for (int i = 0; i < keyArray.Length; i++) { counter = i; timingObject.paramtersWithValues[keyArray[i]] = gridRow.Cells[keyArray[i]].Value; if (string.Equals(keyArray[i], "EXECUTION_TYPE") || string.Equals(keyArray[i], "TE_REF") || string.Equals(keyArray[i], "TEST_PACKAGE") || string.Equals(keyArray[i], "VERSION") || string.Equals(keyArray[i], "BUILD_ID") || string.Equals(keyArray[i], "PAC_STATUS") || string.Equals(keyArray[i], "FUNC_STATUS") || string.Equals(keyArray[i], "BZIP_FILE_PATH") || string.Equals(keyArray[i], "REMOTE_HOST") || string.Equals(keyArray[i], "FILE_NAME") || string.Equals(keyArray[i], "COMMENT") || string.Equals(keyArray[i], "REFERENCE_TYPE") || string.Equals(keyArray[i], "TPK_NICKNAME") || string.Equals(keyArray[i], "TPK_SVN_BRANCH") || string.Equals(keyArray[i], "LOGICAL_TE") || string.Equals(keyArray[i], "SELECTED_TE") || string.Equals(keyArray[i], "TE_GROUP")) { commandInsertToIntermediate.Parameters.Add("@" + keyArray[i], timingObject.paramtersWithValues[keyArray[i]].ToString()); } else { commandInsertToIntermediate.Parameters.Add("@" + keyArray[i], string.IsNullOrEmpty(timingObject.paramtersWithValues[keyArray[i]].ToString()) ? 0 : timingObject.paramtersWithValues[keyArray[i]]); } valuesInsertedToLog = valuesInsertedToLog +" "+keyArray[i]+"="+timingObject.paramtersWithValues[keyArray[i]].ToString(); } commandInsertToIntermediate.ExecuteNonQuery(); //commandUpdateValuesInPacTiming.ExecuteScalar(); valuesInsertedToLog = "Inserted into QA_PAC_REFERENCES_INT values "+valuesInsertedToLog+"\n\n\nUpdated QA_PAC_TIMING on ID="+idInPacTiming; CommonUtils.LogInformation(valuesInsertedToLog); } }
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(); } }