public void MsSqlTest() { DbHelper dbHelper = new MsSQL("test"); using (TransactionScope transactionScope = new TransactionScope()) { for (int i = 0; i < 10; i++) { ContentValues contentValues = new ContentValues(); contentValues.Add("Name", "lsong"); contentValues.Add("Password", "123456"); dbHelper.Insert("myTable", contentValues); } transactionScope.Complete(); } using (Cursor cursor = dbHelper.Query("myTable", null, null, null)) { while (cursor.Next()) { System.Console.Write(cursor[0] + " "); System.Console.Write(cursor[1] + " "); System.Console.Write(cursor[2]); System.Console.WriteLine(); } } System.Console.ReadKey(true); }
private void bunifuThinButton21_Click(object sender, EventArgs e) { DataTable table = database.Select("Signin", null, " Us = '" + txtUser.Text + "' OR Em = '" + txtEmail.Text + "'"); if (table.Rows.Count == 0) { if (txtUser.Text == "" || txtEmail.Text == "" || txtPassword.Text == "" || txtConfirm.Text == "") { MessageBox.Show("Please Fill out Information!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (txtPassword.Text == txtConfirm.Text) { ContentValues data = new ContentValues(); data.Add("Us", txtUser.Text); data.Add("Pass", txtPassword.Text); data.Add("Em", txtEmail.Text); database.Insert("Signin", data); MessageBox.Show("Credentials Inserted Successfully"); } else { MessageBox.Show("Password didn't match!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } } else { MessageBox.Show("Username or Email Already Exists! Please try again"); } }
private void materialRaisedButton1_Click(object sender, EventArgs e) { if (txtTitle.Text == "" || txtDescription.Text == "" || txtImagePath.Text == "" || txtPDFPath.Text == "") { MessageBox.Show("Please Complete All The Fields"); } else { String[] image = txtImagePath.Text.Split('.'); String[] pdf = txtPDFPath.Text.Split('.'); ContentValues values = new ContentValues(); values.Add("Title", txtTitle.Text); values.Add("Image_Path", "Images/" + txtTitle.Text + "." + image[image.Length - 1]); values.Add("PDFPath", "PDFs/" + txtTitle.Text + "." + pdf[pdf.Length - 1]); values.Add("Description", txtDescription.Text); if (lblID.Visible == false) { database.Insert("Module_Data", values); if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/Images/" + txtTitle.Text + "." + image[image.Length - 1])) { File.Copy(txtImagePath.Text, AppDomain.CurrentDomain.BaseDirectory + "/Images/" + txtTitle.Text + "." + image[image.Length - 1]); } if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/PDFs/" + txtTitle.Text + "." + pdf[pdf.Length - 1])) { File.Copy(txtPDFPath.Text, AppDomain.CurrentDomain.BaseDirectory + "/PDFs/" + txtTitle.Text + "." + pdf[pdf.Length - 1]); } MessageBox.Show("Module Added Succesfully"); } else { database.Update("Module_Data", values, " ID = " + lblID.Text); try { if (IMGPATH.Equals(txtImagePath.Text)) { } else if (PDFPATH.Equals(txtPDFPath.Text)) { } else { if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/Images/" + txtTitle.Text + "." + image[image.Length - 1])) { File.Copy(txtImagePath.Text, AppDomain.CurrentDomain.BaseDirectory + "/Images/" + txtTitle.Text + "." + image[image.Length - 1]); } if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "/PDFs/" + pdf[pdf.Length - 1])) { File.Copy(txtPDFPath.Text, AppDomain.CurrentDomain.BaseDirectory + "/PDFs/" + txtTitle.Text + "." + pdf[pdf.Length - 1]); } MessageBox.Show("Updated Added Succesfully"); } } catch (Exception ex) { MessageBox.Show("An error occur " + ex); } } } }
public CheckQuiz(List <String> checkAnswer, String Title) { InitializeComponent(); this.Text = Title; database = new Database(new OleDbConnection(Properties.Settings.Default.ConnectionString), new OleDbCommand()); database.setAdapter(new OleDbDataAdapter()); var materialSkinManager = MaterialSkinManager.Instance; materialSkinManager.AddFormToManage(this); materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT; materialSkinManager.ColorScheme = new ColorScheme(Primary.Cyan800, Primary.Cyan900, Primary.Cyan500, Accent.LightBlue200, TextShade.WHITE); foreach (String a in checkAnswer) { CorrectAnswers answers = new CorrectAnswers(parseString(a)[0], parseString(a)[1], parseString(a)[2], Boolean.Parse(parseString(a)[3])); answers.Top = posY; answers.Left = 4; posY = (answers.Top + answers.Height + 4); this.panel1.Controls.Add(answers); if (Boolean.Parse(parseString(a)[3])) { score++; } } DataTable count = database.Select("Quiz", null, " Quiz_Title = '" + this.Text + "'"); countControls = count.Rows.Count; DataTable table = database.Select("Score", null, " Quiz_Title = '" + this.Text + "'"); DataTable user = database.Select("Signin", null, " Us = '" + Properties.Settings.Default.Username + "'"); table.DefaultView.Sort = "ID"; table = table.DefaultView.ToTable(); ContentValues values = new ContentValues(); values.Add("Quiz_Title", this.Text); values.Add("Score", score + " / " + countControls); values.Add("isPass", score > (countControls / 2) ? "True" : "False"); values.Add("Us", Properties.Settings.Default.Username); values.Add("Email", user.Rows[0]["Em"].ToString()); if (table.Rows.Count != 0) { database.Update("Score", values, " Quiz_Title = '" + this.Text + "'"); } else { database.Insert("Score", values); } timer1.Interval = 1000; timer1.Start(); }
private void materialRaisedButton1_Click(object sender, EventArgs e) { if (!rbAdmin.Checked && !rbStudent.Checked) { MessageBox.Show("Select Account Type!"); } else if (txtUser.Text == "") { MessageBox.Show("Please Enter Username!"); } else if (txtEmail.Text == "") { MessageBox.Show("Please Enter Email!"); } else if (txtPassword.Text == "") { MessageBox.Show("Please Enter Password!"); } else { if (lblID.Visible == true) { ContentValues values = new ContentValues(); values.Add("Account_Type", rbAdmin.Checked ? "Admin" : "User"); values.Add("Us", txtUser.Text); values.Add("Pass", txtPassword.Text); values.Add("Em", txtEmail.Text); database.Update("Signin", values, " ID = " + lblID.Text); } else { ContentValues values = new ContentValues(); values.Add("Account_Type", rbAdmin.Checked ? "Admin" : "User"); values.Add("Us", txtUser.Text); values.Add("Pass", txtPassword.Text); values.Add("Em", txtEmail.Text); database.Insert("Signin", values); } } }
private void materialRaisedButton1_Click(object sender, EventArgs e) { ContentValues values = new ContentValues(); values.Add("Quiz_Title", dropdown.selectedValue); values.Add("QuestionNo", lblNo.Text); values.Add("Question", txtQuestion.Text); String[] choices = txtChoices.Text.Split('\n'); values.Add("A", choices[0]); values.Add("B", choices[1]); values.Add("C", choices[2]); values.Add("D", choices[3]); values.Add("Correct_Answer", txtCorrectAnswer.Text); if (lblID.Visible == false) { database.Insert("Quiz", values); MessageBox.Show("Data Added Succesfully"); } else { database.Update("Quiz", values, " ID = " + lblID.Text); MessageBox.Show("Data Updated Succesfully"); } }