public bool Call400Pgm(string cmdtext, IBM.Data.DB2.iSeries.iDB2Connection cn) { // ------------------------------------------------------------ // This method runs a command on the iSeries using QCMDEXC. // // cmdtext is the command or program you want to call. // cn is an open iDB2Connection the command will be run on. // If the command runs without error, this method returns true. //------------------------------------------------------------ bool rc = true; // Construct a string which contains the call to QCMDEXC. // Because QCMDEXC uses single quote characters, we must // delimit single quote characters in the command text // with an extra single quote. string pgmParm = "CALL QSYS.QCMDEXC('" + cmdtext.Replace("'", "''") + "', " + cmdtext.Length.ToString("0000000000.00000") + ")"; iDB2Command cmd = new iDB2Command(pgmParm, cn); try { cmd.ExecuteNonQuery(); } catch { rc = false; } cmd.Dispose(); return(rc); }
public iDB2DataReader GetDataReaderFromProcedureOnTrans(string strSQLWithoutCALLString, iDB2Parameter[] sqlParameters) { var objCmd = default(iDB2Command); iDB2DataReader drProcedure; try { objCmd = new iDB2Command("{CALL " + strSQLWithoutCALLString + "}", objConnection); objCmd.Transaction = objTransaction; objCmd.CommandType = CommandType.StoredProcedure; foreach (var objPar in sqlParameters) { objCmd.Parameters.Add(objPar); } drProcedure = objCmd.ExecuteReader(); } catch (Exception ex) { drProcedure = default; if (objCmd is object) { objCmd.Dispose(); } objException = ex; } return(drProcedure); }
public iDB2DataReader GetDataReaderFromQuery(string strQuery, CommandType intCommandType) { var objCmd = default(iDB2Command); iDB2DataReader objDr; var objConn = default(iDB2Connection); try { objConn = new iDB2Connection(strConn); objCmd = new iDB2Command(strQuery, objConn); objCmd.CommandType = intCommandType; objConn.Open(); objDr = objCmd.ExecuteReader(CommandBehavior.CloseConnection); } catch (Exception ex) { objDr = default; if (objCmd is object) { objCmd.Dispose(); } if (objConn is object) { objConn.Close(); objConn.Dispose(); } objException = ex; } return(objDr); }
public void EndTransaction(bool blnCommit) { try { if (blnCommit == true) { objTransaction.Commit(); } else { objTransaction.Rollback(); } } catch (Exception ex) { objException = ex; } finally { //objClear.CleanupPooledConnections(); objConnection.Close(); objTransaction.Dispose(); objTransaction = null; blnTrans = false; if (objCommand is object) { objCommand.Dispose(); objCommand = null; } } }
private void getGroupIds() { //remove all preexisting data from the list groupIds.Clear(); //Create connection to the iSeries iDB2Connection cn = new iDB2Connection(); cn.ConnectionString = connectionString; //Create query iDB2Command cmd = new iDB2Command(); cmd.CommandText = "Select group_id from ISSYSDTA.SHORETELINBOUNDGROUPS"; cmd.Connection = cn; cn.Open(); //Execute the sql statement. Get a Data Reader object iDB2DataReader readFile = cmd.ExecuteReader(); //Read each row from the table and output the results while (readFile.Read()) { groupIds.Add(readFile.GetiDB2Integer(0)); } //Clean up - Close connections readFile.Close(); cmd.Dispose(); cn.Close(); }
/// <summary> /// Returns downloaded Dictioanry with UPC codes matching items. /// </summary> public Dictionary <string, string> DownloadUpcForItemsAsync(BindableCollection <IpgModel> _ipgsCollection) { Console.WriteLine("Trying to connect to Reflex for downloading UPC codes..."); // Dictionary for holding Ean to Upc map. Dictionary <string, string> Ean_Upc = new Dictionary <string, string>(); // Preparing a formatted list of items. string _items = ConcatenateItemsIntoList(_ipgsCollection); try { conn.Open(); if (conn != null) { Console.WriteLine("Successfully connected to Reflex for downloading UPC codes"); // Below are DB2 functions needed for executing query string _queryString = $"SELECT VICART, VICIVL FROM {Environment}.HLVLIDP WHERE VICART IN {_items} and VICTYI = 'EAN_1' Order by VICIVL "; iDB2Command comm = conn.CreateCommand(); comm.CommandText = _queryString; iDB2DataReader reader = comm.ExecuteReader(); // Reader in while goes through all rows of results from Reflex. while (reader.Read()) { // Adds new key-value to a Dictionary. Ean_Upc.Add(reader.GetString(0).ToString().Trim(), reader.GetString(1).ToString().Trim()); } Console.WriteLine("Dictionary EAN_UPC created"); // Some cleaning needed. reader.Close(); comm.Dispose(); // Return Dictionary return(Ean_Upc); } } catch (Exception ex) { Console.WriteLine("Error : " + ex); Console.WriteLine(ex.StackTrace); return(null); } finally { conn.Close(); } // This will never reach by needs to be here because of error "Not all is returning value". return(Ean_Upc); }
public DataSet GetDataSetFromProcedure(string strSQLWithoutCALLString, iDB2Parameter[] sqlParameters) { var objDataAd = default(iDB2DataAdapter); var objDs = default(DataSet); var objCmd = default(iDB2Command); var objConn = default(iDB2Connection); try { objConn = new iDB2Connection(strConn); objDataAd = new iDB2DataAdapter(); objCmd = new iDB2Command("{CALL " + strSQLWithoutCALLString + "}", objConn); objDataAd.SelectCommand = objCmd; foreach (var objPar in sqlParameters) { objCmd.Parameters.Add(objPar); } objDs = new DataSet(); objDataAd.Fill(objDs); } catch (Exception ex) { if (objCmd is object) { objCmd.Dispose(); } if (objDs is object) { objDs.Dispose(); } objDs = default; objException = ex; } finally { if (objDataAd is object) { objDataAd.Dispose(); } if (objConn is object) { objConn.Close(); objConn.Dispose(); } } return(objDs); }
public iDB2DataReader GetDataReaderFromQueryOnTrans(string strQuery, CommandType intCommandType) { var objCmd = default(iDB2Command); iDB2DataReader objDr; try { objCmd = new iDB2Command(strQuery, objConnection); objCmd.CommandType = intCommandType; objCmd.Transaction = objTransaction; objDr = objCmd.ExecuteReader(); } catch (Exception ex) { objDr = default; if (objCmd is object) { objCmd.Dispose(); } } return(objDr); }
public void upsertGroup(Group group) { //Create connection to the iSeries iDB2Connection cn = new iDB2Connection(); cn.ConnectionString = connectionString; //Create query iDB2Command cmd = new iDB2Command(); cmd.CommandText = "merge into issysdta.shoreteleccinboundgroupdaily as t " + "using ( values( cast(@groupId as smallint) " + ",cast(@groupName as varchar(40)) " + ",cast(@queuedCallsAboveTasa as smallint) " + ",cast(@queuedCalls as smallint) " + ",cast(@maxQueTime as integer) " + ",cast(@agentsLoggedIn as smallint) " + ",cast(@agentsIdle as smallint) " + ",cast(@acdInCalls as integer) " + ",cast(@tsf as smallint) " + ",cast(@abandonedCalls as integer) " + ")) " + "as zac(group_id " + ", group_name " + ", queued_calls_above_tasa " + ", queued_calls " + ", max_que_time " + ", agents_logged_in " + ", agents_idle " + ", acd_in_calls " + ", tsf " + ", abandoned_calls) " + "on t.group_id = zac.group_id " + "when matched then update " + "set t.group_name = zac.group_name " + ", t.queued_calls_above_tasa = zac.queued_calls_above_tasa " + ", t.queued_calls = zac.queued_calls " + ", t.max_que_time = zac.max_que_time " + ", t.agents_logged_in = zac.agents_logged_in " + ", t.agents_idle = zac.agents_idle " + ", t.acd_in_calls = zac.acd_in_calls " + ", t.tsf = zac.tsf " + ", t.abandoned_calls = zac.abandoned_calls " + "when not matched then " + "insert (group_id " + ", group_name " + ", queued_calls_above_tasa " + ", queued_calls " + ", max_que_time " + ", agents_logged_in " + ", agents_idle " + ", acd_in_calls " + ", tsf " + ", abandoned_calls) " + "values (zac.group_id " + ", zac.group_name " + ", zac.queued_calls_above_tasa " + ", zac.queued_calls " + ", zac.max_que_time " + ", zac.agents_logged_in " + ", zac.agents_idle " + ", zac.acd_in_calls " + ", zac.tsf " + ", zac.abandoned_calls) "; cmd.Connection = cn; cn.Open(); cmd.DeriveParameters(); cmd.Parameters["@groupName"].Value = group.GroupName; cmd.Parameters["@queuedCallsAboveTasa"].Value = Convert.ToInt32(group.InboundAboveTargetAverageSpeedAnswer); cmd.Parameters["@queuedCalls"].Value = Convert.ToInt32(group.InboundCallsInQueue); cmd.Parameters["@maxQueTime"].Value = Convert.ToInt32(group.InboundMaxInQueue); cmd.Parameters["@agentsLoggedIn"].Value = group.NumberOfAgents; cmd.Parameters["@agentsIdle"].Value = group.NumberIdle; cmd.Parameters["@acdInCalls"].Value = group.AutomaticCallDistribution; cmd.Parameters["@tsf"].Value = group.TargetServiceFactor; cmd.Parameters["@abandonedCalls"].Value = group.AbandonedCalls; cmd.Parameters["@groupId"].Value = group.Id; cmd.ExecuteNonQuery(); //Clean up - Close connections cmd.Dispose(); cn.Close(); }
public void Dispose() { command.Dispose(); }
private void updateCampaignMetricData(string metric, string callMethod, string campaign) { //Create connection to the iSeries iDB2Connection cn = new iDB2Connection(); cn.ConnectionString = connectionString; //Create query iDB2Command cmd = new iDB2Command(); cmd.CommandText = "update monprddta.campaignmetrics set Metric = @metric where CallType = @callMethod and Campaign = @campaign"; cmd.Connection = cn; cn.Open(); cmd.DeriveParameters(); cmd.Parameters["@metric"].Value = Convert.ToDecimal(metric); cmd.Parameters["@callMethod"].Value = callMethod; cmd.Parameters["@campaign"].Value = campaign; cmd.ExecuteNonQuery(); //Clean up - Close connections cmd.Dispose(); cn.Close(); }
private void getCampaignMetricData() { //remove all preexisting data from the list campaignMetrics.Clear(); //Create a DataSet to hold data from iSeries Table DataSet dataStructure = new DataSet(); //Create a table to hold the iSeries data DataTable dt = new DataTable("CampaignMetric"); dt.Columns.Add("CampaignName"); dt.Columns.Add("CampaignDisplayName"); dt.Columns.Add("CallMethod"); dt.Columns.Add("Metric"); //Add the datatable to the data set dataStructure.Tables.Add(dt); //Create connection to the iSeries iDB2Connection cn = new iDB2Connection(); cn.ConnectionString = connectionString; //Create query iDB2Command cmd = new iDB2Command(); cmd.CommandText = "select * from monprddta.campaignmetrics"; cmd.Connection = cn; cn.Open(); //Execute the sql statement. Get a Data Reader object iDB2DataReader readFile = cmd.ExecuteReader(); //Read each row from the table and output the results into the data set while (readFile.Read()) { //Create a row to hold data DataRow datarow = dataStructure.Tables["CampaignMetric"].NewRow(); datarow["CallMethod"] = readFile.GetString(0).Trim(); datarow["CampaignName"] = readFile.GetString(1).Trim(); datarow["Metric"] = readFile.GetiDB2Decimal(2); //add the row to the data table Campaigns dataStructure.Tables["CampaignMetric"].Rows.Add(datarow); } //Clean up - Close connections readFile.Close(); cmd.Dispose(); cn.Close(); foreach (DataRow row in dt.Rows) { switch (row["CampaignName"].ToString()) { case "MAS": row["CampaignDisplayName"] = "MAS"; break; case "MASSP": row["CampaignDisplayName"] = "MAS SP"; break; case "MASSS": row["CampaignDisplayName"] = "ALT"; break; case "MASSPS": row["CampaignDisplayName"] = "ALT SP"; break; case "MASFC": row["CampaignDisplayName"] = "FOCUS"; break; case "MASSPFC": row["CampaignDisplayName"] = "FOCUS SP"; break; case "MASWC": row["CampaignDisplayName"] = "WC"; break; case "MASWCSP": row["CampaignDisplayName"] = "WC SP"; break; case "M2GEN": row["CampaignDisplayName"] = "2G"; break; case "M2GSP": row["CampaignDisplayName"] = "2G SP"; break; case "MASPS": row["CampaignDisplayName"] = "BULK"; break; case "2NDPASS": row["CampaignDisplayName"] = "2NDPASS"; break; case "INBOUND": row["CampaignDisplayName"] = "INBOUND"; break; default: //nothing break; } campaignMetrics.Add(new CampaignMetric(row["CampaignName"].ToString(), row["CampaignDisplayName"].ToString(), row["CallMethod"].ToString(), row["Metric"].ToString())); } }
private void getCampaignBucketData() { //remove all preexisting data from the list campaignBuckets.Clear(); //Create a DataSet to hold data from iSeries Table DataSet dataStructure = new DataSet(); //Create a table to hold the iSeries data DataTable dt = new DataTable("CampaignBuckets"); dt.Columns.Add("Campaign"); dt.Columns.Add("Bucket"); dt.Columns.Add("CallMethod"); dt.Columns.Add("Count"); //Add the datatable to the data set dataStructure.Tables.Add(dt); //Create connection to the iSeries iDB2Connection cn = new iDB2Connection(); cn.ConnectionString = connectionString; //Create query iDB2Command cmd = new iDB2Command(); cmd.CommandText = "SELECT bucket, CCPPRJ, 'P' as type , count(rmkey) FROM cdqfil.obpcmt left join monprddta.buckets on char(bucket)<>ccpprj left join cdqfil.crmmas on ccpprj=rmp2prjt and rmacono between digits(bucketmin) and digits(bucketmax) and rmncdt=@Date and rmp2rflg in ('1','H') and rmdnc='' WHERE ccpprj in ('MAS', 'MASSP', 'MASSS', 'MASSPS', 'MASFC', 'MASSPFC') GROUP BY bucket, ccpprj UNION SELECT bucket, CCPPRJ, 'M' as type , count(rmkey) FROM cdqfil.obpcmt left join monprddta.buckets on char(bucket) <> ccpprj left join cdqfil.crmmas on ccpprj = rmp2prjt and rmacono between digits(bucketmin) and digits(bucketmax) and rmncdt = @Date and rmp2rflg in ('M', 'h') and rmdnc = '' WHERE ccpprj in ('MAS', 'MASSP', 'MASSS', 'MASSPS', 'MASFC', 'MASSPFC') GROUP BY bucket, ccpprj ORDER BY type, ccpprj, bucket"; cmd.Connection = cn; //prepare for Date parameter String date = long.Parse(DateTime.Today.Date.ToString("yyyyMMdd")).ToString(); cn.Open(); cmd.DeriveParameters(); cmd.Parameters["@Date"].Value = date; //Execute the sql statement. Get a Data Reader object iDB2DataReader readFile = cmd.ExecuteReader(); //Read each row from the table and output the results into the data set while (readFile.Read()) { //Create a row to hold data DataRow datarow = dataStructure.Tables["CampaignBuckets"].NewRow(); datarow["Bucket"] = readFile.GetString(0).Trim(); datarow["Campaign"] = readFile.GetString(1).Trim(); datarow["CallMethod"] = readFile.GetString(2); datarow["Count"] = readFile.GetString(3); //add the row to the data table Campaigns dataStructure.Tables["CampaignBuckets"].Rows.Add(datarow); } //Clean up - Close connections readFile.Close(); cmd.Dispose(); cn.Close(); foreach (DataRow row in dt.Rows) { switch (row["Campaign"].ToString()) { case "MAS": //do nothing as it's named correctly already break; case "MASSP": row["Campaign"] = "MAS SP"; break; case "MASSS": row["Campaign"] = "ALT"; break; case "MASSPS": row["Campaign"] = "ALT SP"; break; case "MASFC": row["Campaign"] = "FOCUS"; break; case "MASSPFC": row["Campaign"] = "FOCUS SP"; break; default: //nothing break; } campaignBuckets.Add(new CampaignBucket(row["Campaign"].ToString(), row["Bucket"].ToString(), row["CallMethod"].ToString(), row["Count"].ToString())); } }
private void getCampaignData() { //remove all preexisting data from the list campaignData.Clear(); // Create a DataSet to hold data from iSeries Table DataSet dataStructure = new DataSet(); //Create a table to hold the iSeries data DataTable dt = new DataTable("Campaigns"); dt.Columns.Add("CampaignName"); dt.Columns.Add("CampaignDisplayName"); dt.Columns.Add("CallMethod"); dt.Columns.Add("AccountsRemaining"); dt.Columns.Add("InitialAccounts"); //Add the datatable to the data set dataStructure.Tables.Add(dt); //Create connection to the iSeries iDB2Connection cn = new iDB2Connection(); cn.ConnectionString = connectionString; //Create query iDB2Command cmd = new iDB2Command(); cmd.CommandText = "select m.rmp2prjt " + ",m.CallMethod " + ",COALESCE(c.cnt, 0) AS nowAccounts " + ",COALESCE(m.cnt, 0 ) AS initialAccounts " + "FROM " + "(SELECT rmp2prjt " + ",case when rmp2prjt = rmp3prjt Then 'I' when rmp2rflg in ('1', 'H') Then 'P' else 'M' end as CallMethod " + ",count(*) as cnt " + "FROM monprddta.crmmascopy " + "WHERE (rmp2prjt like 'MAS%' or rmp2prjt in ('MS2BW210', 'MSCYC21', 'M2GEN', 'M2GSP')) and rmncdt = @Date and rmp2rflg in ('1','H','M','h') and rmdnc = '' " + "GROUP BY rmp2prjt, case when rmp2prjt = rmp3prjt then 'I' when rmp2rflg in ('1','H') Then 'P' else 'M' end) m " + "LEFT JOIN " + "(SELECT rmp2prjt " + ",case when rmp2prjt = rmp3prjt Then 'I' when rmp2rflg in ('1', 'H') Then 'P' else 'M' end as CallMethod " + ",count(*) as cnt " + "FROM cdqfil.crmmas " + "WHERE (rmp2prjt like 'MAS%' or rmp2prjt in ('MS2BW210', 'MSCYC21', 'M2GEN', 'M2GSP')) and rmncdt = @Date and rmp2rflg in ('1','H','M','h') and rmdnc = '' " + "GROUP BY rmp2prjt, case when rmp2prjt = rmp3prjt then 'I' when rmp2rflg in ('1','H') Then 'P' else 'M' end) c on c.rmp2prjt = m.rmp2prjt and c.callmethod = m.callmethod"; cmd.Connection = cn; //prepare for Date parameter String date = long.Parse(DateTime.Today.Date.ToString("yyyyMMdd")).ToString(); cn.Open(); cmd.DeriveParameters(); cmd.Parameters["@Date"].Value = date; //Execute the sql statement. Get a Data Reader object iDB2DataReader readFile = cmd.ExecuteReader(); //Read each row from the table and output the results into the data set while (readFile.Read()) { //Create a row to hold data DataRow datarow = dataStructure.Tables["Campaigns"].NewRow(); datarow["CampaignName"] = readFile.GetString(0).Trim(); datarow["CallMethod"] = readFile.GetString(1); datarow["AccountsRemaining"] = readFile.GetiDB2Integer(2); datarow["InitialAccounts"] = readFile.GetiDB2Integer(3); //add the row to the data table Campaigns dataStructure.Tables["Campaigns"].Rows.Add(datarow); } //Clean up - Close connections readFile.Close(); cmd.Dispose(); cn.Close(); foreach (DataRow row in dt.Rows) { switch (row["CampaignName"].ToString()) { case "MAS": row["CampaignDisplayName"] = "MAS"; sortId = 0; break; case "MASSP": row["CampaignDisplayName"] = "MAS SP"; sortId = 1; break; case "MASSS": row["CampaignDisplayName"] = "ALT"; sortId = 2; break; case "MASSPS": row["CampaignDisplayName"] = "ALT SP"; sortId = 3; break; case "MASFC": row["CampaignDisplayName"] = "FOCUS"; sortId = 4; break; case "MASSPFC": row["CampaignDisplayName"] = "FOCUS SP"; sortId = 5; break; case "MASWC": row["CampaignDisplayName"] = "WC"; sortId = 6; break; case "MASWCSP": row["CampaignDisplayName"] = "WC SP"; sortId = 7; break; case "M2GEN": row["CampaignDisplayName"] = "2G"; sortId = 8; break; case "M2GSP": row["CampaignDisplayName"] = "2G SP"; sortId = 9; break; case "MASPS": row["CampaignDisplayName"] = "BULK"; sortId = 10; break; case "2NDPASS": row["CampaignDisplayName"] = "2NDPASS"; sortId = 11; break; case "INBOUND": row["CampaignDisplayName"] = "INBOUND"; sortId = 12; break; default: //nothing break; } campaignData.Add(new Campaign(sortId , row["CampaignName"].ToString() , row["CampaignDisplayName"].ToString() , row["CallMethod"].ToString() , row["InitialAccounts"].ToString() , row["AccountsRemaining"].ToString(), "0", "0")); } }
//WCSACCDB /// <summary> /// Returns true if HD exist, and saves this hd in OriginalHdModel instance created in this class. /// If hd is Unknown returns false. /// </summary> public bool DownloadHdFromReflex(string _hd) { Console.WriteLine("Trying to connect to Reflex for downloading HD informations."); try { conn.Open(); if (conn != null) { Console.WriteLine("Successfully connected to Reflex for downloading HD informations."); // Below are DB2 functions needed for executing query // Query join table where we can see lines by items. A2CFAN is telling to DB2 to show only lines value. // You can change it to show CAPO or something else. Result will be in field A2CFAR. // This also needs to be ordered by Item. string _queryString = $"SELECT GECART, GECQAL, A.A2CFAR, GEQGEI, B.A2CFAR FROM {Environment}.HLGEINP " + $"inner join {Environment}.HLCDFAP A on GECART = A.A2CART " + $"inner join {Environment}.HLCDFAP B on GECART = B.A2CART " + $"WHERE GENSUP = '{_hd}' and A.A2CFAN = 'LINE' AND B.A2CFAN = 'STAGIONE'" + "Order by GECART"; iDB2Command comm = conn.CreateCommand(); comm.CommandText = _queryString; iDB2DataReader reader = comm.ExecuteReader(); // Below if checks if there is some data in result. If no then it return false. // That means that HD is Unknown. if (reader.HasRows) { // Reader in while goes through all rows of results from Reflex. while (reader.Read()) { // Here we are adding new IPG to HD object. OriginalHdModel.ListOfIpgs.Add(new IpgModel() { Item = reader.GetString(0).ToString().Trim(), Grade = reader.GetString(1).ToString().Trim(), // Lines is an enum so we need parse string to enum here. Line = (Lines)Enum.Parse(typeof(Lines), reader.GetString(2)), Quantity = reader.GetInt32(3), Season = reader.GetString(4).ToString().Trim() }); } // some cleaning. reader.Close(); comm.Dispose(); // Returns true so we have our data in "OriginalHdModel" instance. return(true); } else { // When there is no data from Reflex return(false); } } } catch (Exception ex) { Console.WriteLine("Error : " + ex); Console.WriteLine(ex.StackTrace); return(false); } finally { conn.Close(); } // This will never reach but needs to be here because of error "Not all is returning value". return(false); }