Example #1
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            txtId.ReadOnly = false;
            btnAdd.Enabled = true;
            string           UpdateCommand = @"UPDATE [Members] SET FirstName=@FirstName ,LastName=@LastName,FatherName=@FatherName , MotherName=@MotherName,PhoneNumber=@PhoneNumber,AffiliationDate=@AffiliationDate,Address=@Address,SchoolId=@SchoolId,Description=@Description WHERE Id=@Id";
            SQLiteConnection connection    = new SQLiteConnection($@"Data Source={ConnectionString()}; Version = 3");
            SQLiteCommand    cmd           = new SQLiteCommand(UpdateCommand, connection);

            cmd.Parameters.AddWithValue("@FirstName", txtName.Text);
            cmd.Parameters.AddWithValue("@FatherName", txtFatherName.Text);
            cmd.Parameters.AddWithValue("@MotherName", txtMotherName.Text);
            cmd.Parameters.AddWithValue("@LastName", txtLastName.Text);
            cmd.Parameters.AddWithValue("@PhoneNumber", txtPhoneNumber.Text);
            string Months = dtp.Value.Month.ToString();
            string Days   = dtp.Value.Day.ToString();
            string Year   = dtp.Value.Year.ToString();

            cmd.Parameters.AddWithValue("@AffiliationDate", $"{Year}-{Months}-{Days}");
            cmd.Parameters.AddWithValue("@Address", txtAddress.Text);
            cmd.Parameters.AddWithValue("@SchoolId", cbxSchool.SelectedIndex + 1);
            cmd.Parameters.AddWithValue(@"Description", txtDescription.Text);
            cmd.Parameters.AddWithValue("@Id", Convert.ToInt32(txtId.Text));
            connection.Open();
            cmd.ExecuteNonQuery();
            connection.Close();
            Filldgv(LoadMemberForm(), dgv);
            SchoolForm frm = new SchoolForm();

            Filldgv(frm.GetSchools(), frm.dgv);
            btnReset.PerformClick();
            MessageBox.Show("تمت تعديل بيانات العضو ", "نجاح", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (!ControlIsValid())
     {
         MessageBox.Show("يرجى تعبئة الحقول الفارغة");
         return;
     }
     else
     {
         SQLiteConnection connection = new SQLiteConnection($@"Data Source={ConnectionString()}; Version = 3");
         using (IDbConnection dbConnection = new SQLiteConnection($@"Data Source={ConnectionString()}; Version = 3"))
         {
             int  Id    = Convert.ToInt32(txtId.Text);
             bool exist = dbConnection.ExecuteScalar <bool>("select count(1) from Schools where Id = @Id", new { Id });
             if (exist)
             {
                 MessageBox.Show("يرجى تغيير رقم العضو", "");
                 return;
             }
         }
         string        InsertCommand = "Insert into [Members] values(@Id,@FirstName,@LastName,@FatherName,@MotherName,@PhoneNumber,@AffiliationDate,@Address,@SchoolId,@Description)";
         SQLiteCommand cmd           = new SQLiteCommand(InsertCommand, connection);
         string        Months        = dtp.Value.Month.ToString();
         string        Days          = dtp.Value.Day.ToString();
         string        Year          = dtp.Value.Year.ToString();
         cmd.Parameters.AddWithValue("@Id", Convert.ToInt32(txtId.Text));
         cmd.Parameters.AddWithValue("@FirstName", Regex.Replace(txtName.Text, @"\s+", " "));
         cmd.Parameters.AddWithValue("@LastName", Regex.Replace(txtLastName.Text, @"\s+", " "));
         cmd.Parameters.AddWithValue("@FatherName", Regex.Replace(txtFatherName.Text, @"\s+", " "));
         cmd.Parameters.AddWithValue("@MotherName", Regex.Replace(txtMotherName.Text, @"\s+", " "));
         cmd.Parameters.AddWithValue("@PhoneNumber", Regex.Replace(txtPhoneNumber.Text, @"\s+", ""));
         cmd.Parameters.AddWithValue("@AffiliationDate", $"{Year}-{Months}-{Days}");
         cmd.Parameters.AddWithValue("@Address", Regex.Replace(txtAddress.Text, @"\s+", " "));
         cmd.Parameters.AddWithValue("@SchoolId", cbxSchool.SelectedIndex + 1);
         cmd.Parameters.AddWithValue("@Description", Regex.Replace(txtDescription.Text, @"\s+", " "));
         connection.Open();
         cmd.ExecuteNonQuery();
         connection.Close();
         Filldgv(LoadMemberForm(), dgv);
         SchoolForm frm = new SchoolForm();
         Filldgv(frm.GetSchools(), frm.dgv);
         btnReset.PerformClick();
         MessageBox.Show("تمت إضافة العضو");
     }
 }
Example #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 Members WHERE Id =@Id";
         SQLiteCommand    cmd           = new SQLiteCommand(DeleteCommand, connection);
         cmd.Parameters.AddWithValue("@Id", Convert.ToInt32(txtId.Text));
         connection.Open();
         cmd.ExecuteNonQuery();
         connection.Close();
         Filldgv(LoadMemberForm(), dgv);
         SchoolForm frm = new SchoolForm();
         Filldgv(frm.GetSchools(), frm.dgv);
         btnReset.PerformClick();
         MessageBox.Show("تمت عملية الحذف بنجاح", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }