|
There are a couple of things I notice about your code. The first thing I see is that you use a switch statement unnecessarily. As each array item you drop into is 1 away from the value in brojKlikova, you can use a simple subtraction to allocate the correct value.
The second issue you have is that you have no idea what's in Tag. It may, or may not, be an int. If I were you, I would use something that is suited to test and convert a value into an int. Specifically, I would use int.TryParse to see if I could actually convert from whatever is in Tag to an int.
int tagValue;
this.trenutneKontrole[brojKlikova-1] = button.Image;
if (!int.TryParse(button.Tag, out tagValue))
{
pokusaj[brojKlikova-1] = tagValue;
}
else
{
System.Diagnostics.Debug.WriteLine("The value in the Tag for {0} is not an integer", brojKlikova);
} Run the application and watch the Output window to see which one of your Tag values triggers this. It's that simple.
This space for rent
|
|
|
|
|
It's like you're running your "code" through an obfuscator before posting it here.
|
|
|
|
|
Take a look below at some of OP's other posts.
|
|
|
|
|
I'm following a tutorial for Web API Jwt Tokens but am confused on what exactly this below code is doing. When I read tutorials, I like to take the time to understand the content rather than just sorta copy/paste blow through them. If anyone is familiar with this type of code, please give me a little walkthrough. I'll go ahead and narrate how I feel this is working below to start it off:
public string Protect(AuthenticationTicket data)
public class CustomJwtFormat : ISecureDataFormat<AuthenticationTicket>
{
private readonly string _issuer = string.Empty;
public CustomJwtFormat(string issuer)
{
_issuer = issuer;
}
public string Protect(AuthenticationTicket data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
string audienceId = ConfigurationManager.AppSettings["as:AudienceId"];
string symmetricKeyAsBase64 = ConfigurationManager.AppSettings["as:AudienceSecret"];
var keyByteArray = TextEncodings.Base64Url.Decode(symmetricKeyAsBase64);
var signingKey = new HmacSigningCredentials(keyByteArray);
var issued = data.Properties.IssuedUtc;
var expires = data.Properties.ExpiresUtc;
var token = new JwtSecurityToken(_issuer, audienceId, data.Identity.Claims, issued.Value.UtcDateTime, expires.Value.UtcDateTime, signingKey);
var handler = new JwtSecurityTokenHandler();
var jwt = handler.WriteToken(token);
return jwt;
}
The code appears to:
1. Accept user claims as an argument called "data" (?)
2. After ensuring the data isn't null, it pulls an "AudienceId" and "AudienceSecret" from AppSettings in web.config and assigns to two variables.
3. It decodes the AudienceSecret from Base64Url into a byte array? <----This is where I'm confused. The secret is just a URL???
4. It now takes the decoded URL and then passes it into a hash function, creating a keyed-hash message authentication code "signing credentials" (also confused a bit here)
5. Assigns issued and expiry date to the claims/data.
6. It then creates a token with the above data
7.News up a "token handler" and then creates yet another jwt token variable and finally apparently receives the token from handler.WriteToken(token)
This is my best guess but there are so many types thrown around here, this code is actually quite difficult to understand, especially coming back to OOP from C; it seems very convoluted with big words and not a ton of meaning.
Any additional info or tips would be appreciated, especially about the "audience." I don't get the relationship between the URL/Base64encoded/string/key thing Thank you!
modified 21-Dec-16 22:10pm.
|
|
|
|
|
The trouble is the developer was too lazy to use proper variable typing, so all those var keywords just make it more difficult to understand. One of the worst decisions in C# was that keyword IMHO.
|
|
|
|
|
I agree with you. It's pretty clear to me that, just like in many other areas/trades, there are many "features" included in modern programming languages which are to be blunt, for lazy people. Or at least abused by them. The thing that always baffles my mind is people do everything they can to try and type less, yet I've never met one programmer whose problem is that they spend too much time typing. In fact, I wished I spent more time typing and less time dealing with bs!
|
|
|
|
|
Go over to QA, and look at the amount of effort some students will put into avoiding learning how to write code: they will invest hours in trying to get you to write a five line console app...
These are the people that want var to be usable outside Linq queries.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
But doesn't everyone want to be a "project manager" ... and skip all that "techie" stuff?
|
|
|
|
|
TheOnlyRealTodd wrote: 3. It decodes the AudienceSecret from Base64Url into a byte array? <----This is where I'm confused. The secret is just a URL???
The secret is a Base64[^]-encoded byte array.
The TextEncodings.Base64Url.Decode method uses Convert.FromBase64String[^]. It replaces some characters that can't be used in a URL, and pads the string to the correct length.
It's not clear why you'd need to do that, since you're not passing the string in a URL.
public class Base64UrlTextEncoder : ITextEncoder
{
public string Encode(byte[] data)
{
if (data == null) throw new ArgumentNullException("data");
return Convert.ToBase64String(data).TrimEnd('=').Replace('+', '-').Replace('/', '_');
}
public byte[] Decode(string text)
{
if (text == null) throw new ArgumentNullException("text");
return Convert.FromBase64String(Pad(text.Replace('-', '+').Replace('_', '/')));
}
private static string Pad(string text)
{
int count = 3 - (text.Length + 3) % 4;
if (count == 0) return text;
return text + new string('=', count);
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'm trying to do an if record exists update statement else insert statement and can't get past the line:
OracleDataReader reader = check_RID.ExecuteReader();
Keep getting ora-00096 missing expression error:
OracleConnection con = new OracleConnection(strConnection);
con.Open();
OracleCommand check_RID = new OracleCommand("SELECT COUNT(*) FROM CONTRACT_INFO WHERE (rid = @rid)", con);
check_RID.Parameters.Add("@rid", labelRID.Text);
OracleDataReader reader = check_RID.ExecuteReader();
if (reader.HasRows)
{
OracleConnection conn = new OracleConnection();
conn.ConnectionString = strConnection;
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "UPDATE...
cmd.ExecuteNonQuery();
conn.Close();
Response.Redirect("primecontractor.aspx?Id=" + labelRID.Text);
}
else
{
OracleConnection conn = new OracleConnection(); // C#
conn.ConnectionString = strConnection;
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "INSERT....
......
cmd.ExecuteNonQuery();
conn.Close();
|
|
|
|
|
From MSDN:
When using named parameters in an SQL statement called by an OracleCommand of CommandType.Text, you must precede the parameter name with a colon . However, in a stored procedure, or when referring to a named parameter elsewhere in your code (for example, when adding OracleParameter objects to the Parameters property), do not precede the named parameter with a colon. The .NET Framework Data Provider for Oracle supplies the colon automatically.
Also rather than execute a reader why not use scalar as COUNT returns a single value test it non-zero.
|
|
|
|
|
AFAIK, the Oracle command uses a : as the parameter prefix, not a @ .
OracleCommand check_RID = new OracleCommand("SELECT COUNT(*) FROM CONTRACT_INFO WHERE (rid = :rid)", con);
check_RID.Parameters.Add("rid", labelRID.Text);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
I have created game with signs.Computer randomly select random combination of four signs to be found.User click button with sign and clicked sign appears in pictureBox.How to make to remove sign in pictureBox when user clicks on it and let him select sign from button again ?
|
|
|
|
|
I set one pictureBox like this, I click button and it removes picture, but when I click button again it adds picture that was before removing and ads new picture from clicked button!!!
private void pBoxIgra00_Click(object sender, EventArgs e)
{
pBoxIgra00.Image = null;
}
|
|
|
|
|
Just Update() the PictureBox after assigning a new image.
pBoxIgra00.Update();
|
|
|
|
|
It does not work.When I click again on button after remove image on first pictureBox it shows image on first pictureBox and on second pictureBox instead of only first pictureBox!!!
|
|
|
|
|
I don't understand your requirement complete - the expaining of the issue is not good
What have you allready coded around this function AND what happens exactly ?
|
|
|
|
|
I added this to pictureBox click.I click button with sign and it appears inside pictureBox,after that I click pictureBox image is removed,after I click other button with sign again it adds two images,in first pictureBox it adds image that was removed and in second pictureBox adds image that I clicked instead of just adding image that I clicked to first pictureBox !!!
private void pBoxIgra00_Click(object sender, EventArgs e)
{
pBoxIgra00.Image = null;
}
|
|
|
|
|
Show your complete code. How do you assign the Image-Property ?
When I tried at on my System it is working as awaited ...
|
|
|
|
|

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Slagalica
{
public partial class Skocko : MetroFramework.Forms.MetroForm
{
public Skocko()
{
InitializeComponent();
}
private SkockoClass objSkocko;
private void Skocko_Load(object sender, EventArgs e)
{
this.objSkocko = new SkockoClass();
}
private void pictureBox14_Click(object sender, EventArgs e)
{
}
private void pictureBox38_Click(object sender, EventArgs e)
{
}
private PictureBox findMyPictureBox(string parPrefix, int parRed, int parKolona)
{
return (PictureBox)base.Controls[string.Format("{2}{0}{1}", parRed, parKolona, parPrefix)];
}
private PictureBox findMyPictureBoxDobitna(int parBroj)
{
return (PictureBox)base.Controls[string.Format("pBoxDobitna{0}", parBroj)];
}
private void OsvezipBoxIgra()
{
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 4; j++)
{
if (this.objSkocko.glavnaMatrica[i, j] != 100)
{
PictureBox pictureBox = this.findMyPictureBox("pBoxIgra", i, j);
pictureBox.Image = this.imageList1.Images[this.objSkocko.glavnaMatrica[i, j]];
}
}
}
}
private void OsvezipBoxRezultat()
{
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 4; j++)
{
if (this.objSkocko.rezultatMatrica[i, j] != 100)
{
PictureBox pictureBox = this.findMyPictureBox("pBoxRezultat", i, j);
if (this.objSkocko.rezultatMatrica[i, j] == 1)
{
pictureBox.BackColor = Color.Yellow;
}
else
{
pictureBox.BackColor = Color.Red;
}
}
}
}
}
private void OsvezipBoxDobitna()
{
for (int i = 0; i < 4; i++)
{
PictureBox pictureBox = this.findMyPictureBoxDobitna(i);
pictureBox.Image = this.imageList1.Images[this.objSkocko.dobitnaKombinacija[i]];
}
}
private void Igraj(int parZnak)
{
this.objSkocko.Igraj(parZnak);
this.OsvezipBoxIgra();
this.OsvezipBoxRezultat();
if (this.objSkocko.Pobeda)
{
this.OsvezipBoxDobitna();
if (MessageBox.Show("POBEDILI STE!!!\nNova igra?", "POBEDA", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
Application.Restart();
}
else
{
Application.Exit();
}
}
if (this.objSkocko.trenutniPotez == 23)
{
this.OsvezipBoxDobitna();
if (MessageBox.Show("IZGUBILI STE!!!\nNova igra?", "PORAZ", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
Application.Restart();
}
else
{
Application.Exit();
}
}
}
private void btnIgrajSkocko_Click(object sender, EventArgs e)
{
this.Igraj(0);
}
private void btnIgrajZvezda_Click(object sender, EventArgs e)
{
this.Igraj(1);
}
private void btnIgrajPik_Click(object sender, EventArgs e)
{
this.Igraj(2);
}
private void btnIgrajKaro_Click(object sender, EventArgs e)
{
this.Igraj(3);
}
private void btnIgrajHerc_Click(object sender, EventArgs e)
{
this.Igraj(4);
}
private void btnIgrajTref_Click(object sender, EventArgs e)
{
this.Igraj(5);
}
}
}
Other class with code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Slagalica
{
class SkockoClass
{
public int trenutniPotez;
public int[,] glavnaMatrica;
public int[,] rezultatMatrica;
public int[] dobitnaKombinacija;
public bool Pobeda;
public SkockoClass()
{
this.Pobeda = false;
this.trenutniPotez = -1;
this.InicijalizacijaMatrice();
this.GenerisiDobitnuKombinaciju();
}
public void Igraj(int parIzabrano)
{
this.trenutniPotez++;
int num = Convert.ToInt32(Math.Floor((double)this.trenutniPotez / 4.0));
int num2 = this.trenutniPotez % 4;
this.glavnaMatrica[num, num2] = parIzabrano;
if (this.trenutniPotez % 4 == 3)
{
this.Provera(num);
}
}
public void Provera(int parRed)
{
int[] array = new int[4];
int[] array2 = new int[4];
for (int i = 0; i < 4; i++)
{
array[i] = this.glavnaMatrica[parRed, i];
array2[i] = this.dobitnaKombinacija[i];
}
int num = 0;
for (int i = 0; i < 4; i++)
{
if (array[i] == array2[i])
{
num++;
array[i] = 100;
array2[i] = 100;
}
}
int num2 = 0;
for (int i = 0; i < 4; i++)
{
if (array[i] != 100)
{
for (int j = 0; j < 4; j++)
{
if (array2[j] != 100 && array2[j] == array[i])
{
num2++;
array[i] = 100;
array2[j] = 100;
}
}
}
}
if (num == 4)
{
this.Pobeda = true;
}
this.PuniZuteCrvene(parRed, num2, num);
}
public void PuniZuteCrvene(int parRed, int parZutih, int parCrvenih)
{
int num = -1;
for (int i = 0; i <= parCrvenih - 1; i++)
{
this.rezultatMatrica[parRed, ++num] = 0;
}
for (int i = 0; i <= parZutih - 1; i++)
{
this.rezultatMatrica[parRed, ++num] = 1;
}
}
public void GenerisiDobitnuKombinaciju()
{
this.dobitnaKombinacija = new int[4];
Random random = new Random();
for (int i = 0; i < 4; i++)
{
this.dobitnaKombinacija[i] = random.Next(0, 6);
}
}
private void InicijalizacijaMatrice()
{
this.glavnaMatrica = new int[6, 4];
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 4; j++)
{
this.glavnaMatrica[i, j] = 100;
}
}
this.rezultatMatrica = new int[6, 4];
for (int i = 0; i < 6; i++)
{
for (int j = 0; j < 4; j++)
{
this.rezultatMatrica[i, j] = 100;
}
}
}
}
}
|
|
|
|
|
Sorry ... at first :
A lot of descriptions in your code are not understandable for me (because of your mother-language - Croatia ?).
What I missed was the code-part with which you have a Problem - the part where the Image-assignment is changed ...
|
|
|
|
|
public void FillCompVouType()
{
try
{
this.Cursor = Cursors.WaitCursor;
con = new SqlConnection(cs.sourceConn1);
con.Open();
scmd = new SqlCommand("Select Distinct VouType From Table_name Where Colum=1 order by VouType", con);
SqlDataReader DR = default(SqlDataReader);
vochcombox.Items.Clear();
DR = scmd.ExecuteReader();
foreach (int VouType in DR)
{
vochcombox.Items.Add(VouType);
}
while (DR.Read())
{
this.vochcombox.Items.Add(DR.GetOrdinal("VouType"));
}
DR.Close();
con.Close();
this.Cursor = Cursors.Default;
}
catch (Exception ex)
{
this.Cursor = Cursors.Default;
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
|
|
|
|
|
Which line is it complaining about? I see no explicit casts in there.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
foreach (int VouType in DR)
|
|
|
|
|