Esempio n. 1
0
 private void ButtonDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Delete Data", "Are You Sure?", MessageBoxButtons.YesNo) == DialogResult.Yes)
     {
         var query = "delete from groups where id = '" + id_group + "'";
         SqlService.ExecuteQuery(query);
         LogApp.Delete("users", DgvRowToString.Generate(dgv, dgv.CurrentRow.Index), "");
         Reload();
     }
 }
Esempio n. 2
0
        private void ButtonSave_Click(object sender, EventArgs e)
        {
            ModSqlCommand command;

            if (RadioButtonAktif.Checked)
            {
                status = "1";
            }
            else
            {
                status = "0";
            }

            if (RadioButtonMale.Checked)
            {
                gender = "M";
            }
            else
            {
                gender = "P";
            }
            var stream = new MemoryStream();

            PictureBoxProfile.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            var pic = stream.ToArray();

            if (!ButtonEdit.Enabled)
            {
                command = SqlService.GetCommand("insert into users (userid,name,email,nohp,address,avatar,gender,status,password,password_noencrypt,token)values('" + Utilities.ReplaceQuot(TextBoxUserId.Text) + "', '" + Utilities.ReplaceQuot(TextBoxName.Text) + "', '" + Utilities.ReplaceQuot(TextBoxEmail.Text) + "', '" + Utilities.ReplaceQuot(TextBoxNohp.Text) + "', '" + Utilities.ReplaceQuot(TextBoxAddress.Text) + "', @Pic, '" + gender + "', '" + status + "', '" + Utilities.GetHashMD5(TextBoxPassword.Text) + "', '" + Utilities.ReplaceQuot(TextBoxPassword.Text) + "', '-')");
                command.sqlCommand.Parameters.AddWithValue("@Pic", pic);
                command.sqlCommand.ExecuteNonQuery();
                command.sqlConnection.Close();
                Reload();
                //Fungsi Mengambil data terbaru
                var indexRow = Convert.ToInt32(SqlService.GetDataTable("select top 1 id,name,ROW_NUMBER() OVER(ORDER BY name) as idx from users order by id desc").Rows[0][2]) - 1;
                LogApp.Insert("users", DgvRowToString.Generate(dgv, indexRow), "");
            }
            else
            {
                command = SqlService.GetCommand("update users set userid='" + Utilities.ReplaceQuot(TextBoxUserId.Text) + "',name='" + Utilities.ReplaceQuot(TextBoxName.Text) + "',email='" + Utilities.ReplaceQuot(TextBoxEmail.Text) + "', nohp='" + Utilities.ReplaceQuot(TextBoxNohp.Text) + "', address = '" + Utilities.ReplaceQuot(TextBoxAddress.Text) + "', avatar = @Pic, gender = '" + gender + "', status = '" + status + "', password_noencrypt = '" + Utilities.ReplaceQuot(TextBoxPassword.Text) + "', password = '******' where id = '" + id_user + "'");
                command.sqlCommand.Parameters.AddWithValue("@Pic", pic);
                LogApp.Update("users", DgvRowToString.Generate(dgv, dgv.CurrentRow.Index), "-", "");
                command.sqlCommand.ExecuteNonQuery();
                command.sqlConnection.Close();
                Reload();
            }
        }