TIMER/ŠTOPERICA
DateTime endTime = new DateTime(YY, MM, DD, HH, MIN, SS);
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(ticker);
timer.Start();
async void ticker(object sender, EventArgs e)
{
TimeSpan timespan = endTime.Subtract(DateTime.Now);
label1.Text = $”Do promocije je ostalo još {timespan.ToString(“d’ dana ‘h’ sati ‘m’ minuta i ‘s’ sekundi'”)}”;
}
DATEPICKER
private void DodajDogadjaj_Load(object sender, EventArgs e)
{
dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = “MM/dd/yyyy hh:mm:ss”;
}
FREEZAJ EKRAN Thread.Sleep(1000);
DOHVAĆANJE SLIKE Image image=Image.FromFile(rdr[“STUPAC”].ToString());
POSTAVLJANJE VELIČINE SLIKE
public static Image ResizeImage(Image img, int width, int height)
{
var b = new Bitmap(width, height);
using (var g = Graphics.FromImage(b))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(img, 0, 0, width, height);
}
return b;
}
RANDOM GENERIRANJE ŠIFRE
public class KeyGenerator
{
internal static readonly char[] chars =
“abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890”.ToCharArray();
public static string GetUniqueKey(int size)
{
byte[] data = new byte[4 * size];
using (var crypto = RandomNumberGenerator.Create())
{
crypto.GetBytes(data);
}
StringBuilder result = new StringBuilder(size);
for (int i = 0; i < size; i++)
{
var rnd = BitConverter.ToUInt32(data, i * 4);
var idx = rnd % chars.Length;
result.Append(chars[idx]);
}
return result.ToString();
}
}
PROVJERI JE LI IMA VELIKO SLOVO I BROJ
static bool IsLetter(char c)
{
return c >= ‘A’ && c <= ‘Z’;
}
static bool IsDigit(char c)
{
return c >= ‘0’ && c <= ‘9’;
}
static bool IsValidPassword(string password)
{
return
password.Any(c => IsLetter(c)) &&
password.Any(c => IsDigit(c));
}
string key = KeyGenerator.GetUniqueKey(10);
while(IsValidPassword(key) == false) { key = KeyGenerator.GetUniqueKey(10); }
HASHIRANJE ŠIFRE U MD5 OBLIKU
MD5CryptoServiceProvider cryptoServiceProvider = new MD5CryptoServiceProvider();
UTF8Encoding utf8Encoding = new UTF8Encoding();
byte[] hash = cryptoServiceProvider.ComputeHash(utf8Encoding.GetBytes(sifraBox.Text));
string[] password = BitConverter.ToString(hash).ToLower().Split(‘-‘);
string sifra = String.Join(“”, password);
POSTAVLJANJE SLIKE
OpenFileDialog opnfd = new OpenFileDialog();
opnfd.Filter = “Image Files (*.jpg;*.jpeg;)|*.jpg;*.jpeg;”;
if (opnfd.ShowDialog() == DialogResult.OK)
{
Image image = Image.FromFile(“” + opnfd.FileName);
dataGridView1[e.ColumnIndex, e.RowIndex].Value = ResizeImage(image, 200, 100);
…
}
POSTAVLJANJE VELIČINA SLOVA U FONT DIALOG
lstPeople.Font = new Font(lstPeople.Font.FontFamily, lstPeople.Font.Size – 1, lstPeople.Font.Style);
SELEKTIRANJE VIŠE CHECKBOX
var whereClause = string.Join(” OR “, selectedGenres.Select(genre => $”vrsta = ‘{genre}'”));
string sql = $”SELECT * FROM worldSkills.Prodaja WHERE {whereClause} AND izdavac LIKE ‘{izdavacInput.Text}%'”;
OTVARANJE FORME
this.Hide();
new FormaZaVoditelje().Show();
DODAVANJE PARAMETRE
cmd.Parameters.AddWithValue(“@email”, emailBox.Text);
STVARANJE DATAGRIDVIEW
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataTable dataTable = new DataTable();
adapter.Fill(dataTable);
dataGridView1.Columns[“Napomena”].DataPropertyName = “Tekst”;
dataGridView1.DataSource = dataTable;
MAX WINDOW SCREEN
this.WindowState = FormWindowState.Maximized;
DIALOG YES/NO
DialogResult dialogResult = MessageBox.Show(“Želite li izbrisati”, “IZBRIŠI”, MessageBoxButtons.YesNo)
DODAVANJE U CHART (PIE CHART)
chart1.Series[“s1”].Points.AddXY(“1”, “20”);
SQL SPAJANJE RAZLIČITIH COLUMNS
STRING_AGG(N.Tekst,’ ‘) AS Tekst
CONVERT DATUM
CONVERT(datetime, @date)