示例#1
0
 private void btn_DeactiveMember_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         object item = DataGrid_Members.SelectedItem;
         this.UserId = 0;
         if (item != null)
         {
             this.UserId = Convert.ToInt32((DataGrid_Members.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text);
             string UserFullName = (DataGrid_Members.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text;
             if (!string.IsNullOrEmpty(UserFullName))
             {
                 if (MessageBox.Show("Are you sure ? ", "Disable", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                 {
                     using (fitnessEntities db = new fitnessEntities(dbConnection.ConnectionString))
                     {
                         db.disableUserMember(this.UserId, 0);
                         db.SaveChanges();
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error : \n\n\n + " + ex.ToString());
     }
     finally
     {
         this.StatusSearch = 1; //Normal Search
         LoadMembersData(GenerateSearchKey);
         LoadExpireMembers();
     }
 }
示例#2
0
 public static void DelCustomer(string Id)
 {
     using (fitnessEntities dbe = new fitnessEntities())
     {
         customer customer = dbe.customers.Where(o => o.customer_id.Equals(Id)).SingleOrDefault();
         dbe.customers.Remove(customer);
         dbe.SaveChanges();
     }
 }
 public static void DelAdmin(string Id)
 {
     using (fitnessEntities dbe = new fitnessEntities())
     {
         admin admin = dbe.admins.Where(o => o.admin_id.Equals(Id)).SingleOrDefault();
         dbe.admins.Remove(admin);
         dbe.SaveChanges();
     }
 }
示例#4
0
 public static void DelEquipment(string Id)
 {
     using (fitnessEntities dbe = new fitnessEntities())
     {
         equipment equipment = dbe.equipments.Where(o => o.equipment_id.Equals(Id)).SingleOrDefault();
         dbe.equipments.Remove(equipment);
         dbe.SaveChanges();
     }
 }
示例#5
0
        private void btn_Delete_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                object item = DataGrid_Members.SelectedItem;
                this.UserId = 0;
                if (item != null)
                {
                    this.UserId = Convert.ToInt32((DataGrid_Members.SelectedCells[0].Column.GetCellContent(item) as TextBlock).Text);
                    string UserFullName = (DataGrid_Members.SelectedCells[1].Column.GetCellContent(item) as TextBlock).Text;
                    if (!string.IsNullOrEmpty(UserFullName))
                    {
                        if (MessageBox.Show("Are you sure ? ", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                        {
                            //todo Delete member with Query
                            using (fitnessEntities db = new fitnessEntities(dbConnection.ConnectionString))
                            {
                                using (TransactionScope ts = new TransactionScope())
                                {
                                    var querySelectAuthUser  = db.Database.SqlQuery <vw_AuthUsers>("select * From vw_AuthUsers where PK_users_Id=" + this.UserId + " and FK_user_Auth_role_Id=1");
                                    var resultSelectAuthUser = querySelectAuthUser.ToList();
                                    if (resultSelectAuthUser.Count == 1)
                                    {
                                        MessageBox.Show("You can not delete this user, this user is the system admin !");
                                        return;
                                    }
                                    else
                                    {
                                        db.DeleteFromMemberInfo(UserId);
                                        db.DeleteFromUsers(UserId);
                                        db.SaveChanges();
                                    }

                                    ts.Complete();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : \n\n\n " + ex.ToString());
            }
            finally
            {
                this.StatusSearch = 1; //Normal Search
                //Reload Data
                LoadMembersData(GenerateSearchKey);
                LoadExpireMembers();
            }
        }
示例#6
0
 public static bool DelTrainer(string Id)
 {
     using (fitnessEntities dbe = new fitnessEntities())
     {
         var cst = dbe.customers.Where(o => o.trainer_id == Id).ToList();
         if (cst.Count == 0)
         {
             trainer trainer = dbe.trainers.Where(o => o.trainer_id.Equals(Id)).SingleOrDefault();
             dbe.trainers.Remove(trainer);
             dbe.SaveChanges();
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
示例#7
0
        private void Btn_New_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!checkNullable())
                {
                    return;
                }
                else
                {
                    if (this.btnAddOrUpdate == 1) // For New
                    {
                        //todo add new member with query
                        using (fitnessEntities db = new fitnessEntities(dbConnection.ConnectionString))
                        {
                            using (TransactionScope ts = new TransactionScope())
                            {
                                var querySelectMember  = db.Database.SqlQuery <VW_members>("select * From VW_members where  FullName =N'" + txt_ShowFirstName.Text.Trim() + ' ' + txt_ShowLastName.Text.Trim() + "'");
                                var resultSelectMember = querySelectMember.ToList();
                                if (resultSelectMember.Count == 1)
                                {
                                    MessageBox.Show("User Exist ! ");
                                    return;
                                }
                                else
                                {
                                    //Save Members info Part 1
                                    db.addMember(
                                        txt_ShowFirstName.Text.Trim(),
                                        txt_ShowLastName.Text.Trim(),
                                        txt_phoneNumber.Text.Trim(),
                                        txt_address.Text.Trim(),
                                        String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"))) +
                                        ' ' +
                                        String.Format("{0:HH:mm:ss}", Convert.ToDateTime(DateTime.Now.ToString("hh:mm:ss"))),
                                        1,
                                        txt_Description.Text.Trim()
                                        );
                                    db.SaveChanges();
                                    //select Id New Member

                                    var querySelectMemberId  = db.Database.SqlQuery <User>("select * From Users where  users_FirstName Like N'%" + txt_ShowFirstName.Text.Trim() + "%' and users_LastName Like N'%" + txt_ShowLastName.Text.Trim() + "%'");
                                    var resultSelectMemberId = querySelectMemberId.ToList();

                                    if (resultSelectMemberId.Count == 0)
                                    {
                                        MessageBox.Show("Transaction Canceled !");
                                        return;
                                    }
                                    //Save Members info Part 2
                                    db.AddmemberInfo(resultSelectMemberId[0].PK_users_Id,
                                                     Convert.ToDouble(txt_Height.Text.Trim()),
                                                     Convert.ToDouble(txt_Weight.Text.Trim()),
                                                     Convert.ToDouble(txt_waistMeasure.Text.Trim()),
                                                     String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(date_Start.Text)) +
                                                     ' ' +
                                                     String.Format("{0:HH:mm:ss}", Convert.ToDateTime(DateTime.Now.ToLongTimeString())),
                                                     String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(date_End.Text)) +
                                                     ' ' +
                                                     String.Format("{0:HH:mm:ss}", Convert.ToDateTime(DateTime.Now.ToLongTimeString())),
                                                     "",
                                                     Convert.ToInt32(txt_Age.Text.Trim()),
                                                     Convert.ToDecimal(txt_MonthlyAmount.Text.Trim()),
                                                     Convert.ToDouble(this.BMRResult),
                                                     Convert.ToDouble(this.BMIResult),

                                                     String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"))) +
                                                     ' ' +
                                                     String.Format("{0:HH:mm:ss}", Convert.ToDateTime(DateTime.Now.ToString("hh:mm:ss"))),
                                                     cmb_exerciesLevel.SelectedIndex,
                                                     cmb_exerciesLevel.Text
                                                     );
                                    db.SaveChanges();



                                    MessageBox.Show("Save Successed !");
                                }
                                ClearData();
                                ts.Complete();
                            }
                        }
                    }
                    else if (this.btnAddOrUpdate == 2) // For update
                    {
                        //todo update member with query
                        if (this.UserId > 0) //Select Member
                        {
                            using (fitnessEntities db = new fitnessEntities(dbConnection.ConnectionString))
                            {
                                using (TransactionScope ts = new TransactionScope())
                                {
                                    db.updateMember(
                                        this.UserId, txt_ShowFirstName.Text.Trim(), txt_ShowLastName.Text.Trim(), txt_phoneNumber.Text.Trim(), txt_address.Text.Trim(), 1, txt_Description.Text
                                        );
                                    db.SaveChanges();


                                    db.updateMemberInfo(
                                        this.UserId,
                                        Convert.ToDouble(txt_Height.Text.Trim()),
                                        Convert.ToDouble(txt_Weight.Text.Trim()),
                                        Convert.ToDouble(txt_waistMeasure.Text.Trim()),
                                        String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(date_Start.Text)) +
                                        ' ' +
                                        String.Format("{0:HH:mm:ss}", Convert.ToDateTime(DateTime.Now.ToLongTimeString())),

                                        String.Format("{0:yyyy-MM-dd}", Convert.ToDateTime(date_End.Text)) +
                                        ' ' +
                                        String.Format("{0:HH:mm:ss}", Convert.ToDateTime(DateTime.Now.ToLongTimeString())),
                                        "", Convert.ToInt32(txt_Age.Text.Trim()),
                                        Convert.ToDecimal(txt_MonthlyAmount.Text.Trim()),
                                        this.BMRResult,
                                        this.BMIResult,
                                        cmb_exerciesLevel.SelectedIndex,
                                        cmb_exerciesLevel.Text
                                        );
                                    db.SaveChanges();

                                    MessageBox.Show("Update Success !");
                                    this.btnAddOrUpdate = 1;
                                    Btn_New.Content     = "New";
                                    ClearData();
                                    ts.Complete();
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : \n\n\n " + ex.ToString());
            }
            finally
            {
                LoadMembersData(GenerateSearchKey);
                LoadExpireMembers();
            }
        }