Exemplo n.º 1
0
 private void btnAdd_Click(object sender, EventArgs e)
 {
     if (!ValidControl())
     {
         return;
     }
     else
     {
         using (IDbConnection dbConnection = new SQLiteConnection($@"Data Source={ConnectionString()}; Version = 3"))
         {
             string name  = txtName.Text;
             bool   exist = dbConnection.ExecuteScalar <bool>("select count(1) from Schools where name = @name", new { name });
             if (exist)
             {
                 MessageBox.Show("المدرسة موجودة بالفعل");
                 return;
             }
             string insert = "INSERT INTO Schools values(@Id,@name,@address,@Manager,@ManagerPhone,@SchoolPhone,0)";
             School school = new School();
             school.FillData(Convert.ToInt32(txtId.Text), Regex.Replace(txtName.Text, @"\s+", " "), Regex.Replace(txtAddress.Text, @"\s+", " "), Regex.Replace(txtNameManager.Text, @"\s+", " "), txtNumberOfManager.Text, txtNumberOfSchool.Text);
             dbConnection.Execute(insert, school);
         }
         string namemessage = txtName.Text;
         btnReset.PerformClick();
         Filldgv(GetSchools(), dgv);
         MemberForm frm = new MemberForm();
         Filldgv(frm.LoadMemberForm(), frm.dgv);
         frm.LoadComboBox();
         MessageBox.Show($"تم إضافة مدرسة {namemessage} ");
     }
 }
Exemplo n.º 2
0
 private void btnEdit_Click(object sender, EventArgs e)
 {
     if (!ValidControl())
     {
         return;
     }
     else
     {
         txtId.ReadOnly = false;
         btnAdd.Enabled = true;
         SQLiteConnection connection = new SQLiteConnection($@"Data Source={ConnectionString()}; Version = 3");
         try
         {
             string        UpdateCommand = "UPDATE Schools SET name=@name ,address=@address,manager=@manager,managerPhone=@managerPhone,schoolPhone=@schoolPhone WHERE Id=@Id";
             SQLiteCommand cmd           = new SQLiteCommand(UpdateCommand, connection);
             cmd.Parameters.AddWithValue("@name", txtName.Text);
             cmd.Parameters.AddWithValue("@address", txtAddress.Text);
             cmd.Parameters.AddWithValue("@manager", txtNameManager.Text);
             cmd.Parameters.AddWithValue("@managerPhone", txtNumberOfManager.Text);
             cmd.Parameters.AddWithValue("@schoolPhone", txtNumberOfSchool.Text);
             cmd.Parameters.AddWithValue("@id", txtId.Text);
             connection.Open();
             cmd.ExecuteNonQuery();
             Filldgv(GetSchools(), dgv);
             MemberForm frm = new MemberForm();
             Filldgv(frm.LoadMemberForm(), frm.dgv);
             frm.LoadComboBox();
             btnReset.PerformClick();
             MessageBox.Show("تم إجراء التعديل بنجاح", "نجاح", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             connection.Close();
         }
     }
 }
Exemplo n.º 3
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("هل تريد حذف هذا السجل", "حذف", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
     {
         SQLiteConnection connection    = new SQLiteConnection($@"Data Source={ConnectionString()}; Version = 3");
         string           DeleteCommand = "DELETE FROM [Schools] WHERE Id = @Id";
         SQLiteCommand    cmd           = new SQLiteCommand(DeleteCommand, connection);
         cmd.Parameters.AddWithValue("@Id", Convert.ToInt32(txtId.Text));
         connection.Open();
         cmd.ExecuteNonQuery();
         connection.Close();
         Filldgv(GetSchools(), dgv);
         MemberForm frm = new MemberForm();
         Filldgv(frm.LoadMemberForm(), frm.dgv);
         frm.LoadComboBox();
         btnReset.PerformClick();
         MessageBox.Show("تمت عملية الحذف بنجاح", "نجاح", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else
     {
         btnReset.PerformClick();
     }
 }