private void button2_Click(object sender, EventArgs e) { Function.CekTextboxComboBox(this, errorProvider1); this.Text = Function.KOSONGTEXT.ToString() + " " + Function.KOSONGKOMBO.ToString(); if ((Function.KOSONGTEXT == false) & (Function.KOSONGKOMBO == false)) { MySql.QUERY = "SELECT * FROM t_user WHERE username='******'"; MySql.Reader(MySql.QUERY); if (MySql.ReaderHasRow == true) { if (input_md5_pass.Text == MySql.ReaderData[2]) { Function.USERDATA[0] = MySql.ReaderData[1]; Function.USERDATA[1] = MySql.ReaderData[3]; Function.USERDATA[2] = MySql.ReaderData[4]; Function.ClearTextBoxComboBox(this); Function.Pesan.Pupup("Berhasil Login !\n - Username : "******"\n - Nama : " + Function.USERDATA[1] + "\n - Level : " + Function.USERDATA[2]); MySql.ShowDataQuery("SELECT * FROM t_user", dataGridView1); } else { errorProvider1.SetError(input_md5_pass, "Password Salah !"); input_md5_pass.Select(); input_md5_pass.SelectAll(); } } else { errorProvider1.SetError(input_user, "Username Tidak ditemukan !"); input_user.Select(); input_user.SelectAll(); } } }
public static string GetAllInput(Control control, string prefix = "input_") { string field, value, resultfield, resultvalue, namecontrol, data, ismd5, isbase64enc; field = ""; value = ""; foreach (Control inputcontrol in control.Controls) { if (inputcontrol.Name.Length > prefix.Length) { namecontrol = inputcontrol.Name.Substring(0, prefix.Length); if (namecontrol == prefix) { ismd5 = inputcontrol.Name.Substring((prefix.Length - 1), 5); isbase64enc = inputcontrol.Name.Substring((prefix.Length - 1), 5); if (ismd5.ToLower() == "_md5_") { field += "`" + inputcontrol.Name.Substring((prefix.Length + 4)) + "`,"; value += "'" + Hash.MD5(inputcontrol.Text) + "',"; } else if (isbase64enc.ToLower() == "_base64enc_") { field += "`" + inputcontrol.Name.Substring((prefix.Length + 10)) + "`,"; value += "'" + Decrypt.Base64(inputcontrol.Text) + "',"; } else if (inputcontrol is DateTimePicker) { DateTimePicker dateTimePicker = inputcontrol as DateTimePicker; field += "`" + inputcontrol.Name.Substring(prefix.Length) + "`,"; value += "'" + dateTimePicker.Value.ToString("yyyy-MM-dd") + "',"; } else { field += "`" + inputcontrol.Name.Substring(prefix.Length) + "`,"; value += "'" + MySql.EscapeString(inputcontrol.Text) + "',"; } } } } resultfield = field.Substring(0, field.Length - 1); resultvalue = value.Substring(0, value.Length - 1); data = "(" + resultfield + ") VALUES (" + resultvalue + ")"; return(data); }
public static string GetAllUpdate(Control control, string prefix = "input_") { string field, value, resultfield, resultvalue, result, namecontrol, data, ismd5; result = ""; foreach (Control inputcontrol in control.Controls) { if (inputcontrol.Name.Length > prefix.Length) { namecontrol = inputcontrol.Name.Substring(0, prefix.Length); if (namecontrol == prefix) { ismd5 = inputcontrol.Name.Substring((prefix.Length - 1), 5); if (ismd5.ToLower() == "_md5_") { field = "`" + inputcontrol.Name.Substring((prefix.Length + 4)) + "`,"; value = "'" + Hash.MD5(inputcontrol.Text) + "',"; } else if (inputcontrol is DateTimePicker) { DateTimePicker dateTimePicker = inputcontrol as DateTimePicker; field = "`" + inputcontrol.Name.Substring(prefix.Length) + "`,"; value = "'" + dateTimePicker.Value.ToString("yyyy-MM-dd") + "',"; } else { field = "`" + inputcontrol.Name.Substring(prefix.Length) + "`,"; value = "'" + MySql.EscapeString(inputcontrol.Text) + "',"; } resultfield = field.Substring(0, field.Length - 1); resultvalue = value.Substring(0, value.Length - 1); result += resultfield + " = " + resultvalue + ", "; } } } data = result.Substring(0, result.Length - 2); return(data); }