Beispiel #1
0
        private void btnPhoneDelete_Click(object sender, EventArgs e)
        {
            DataBaseDataContext myConnection = Setting.DataBase;

            if (lstPhoneNumber.SelectedItems.Count == 0)
            {
                DataValidationMesaage.NoSelectedItemFromList("لیست شماره های تماس");

                return;
            }

            #region Member Casting

            int memberId = FrmMember.MemberProfile.ID;

            if (!Member.Validation(memberId, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            Member member = Member.Get(memberId, myConnection);

            #endregion

            #region Phone Casting

            int phoneId = ((Phone)cmbPhone.SelectedItem).ID;

            if (!Phone.Validation(phoneId, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            Phone phone = Phone.Get(phoneId, myConnection);

            #endregion

            #region PhoneNumber Casting

            PhoneNumber phoneNumber = (PhoneNumber)lstPhoneNumber.SelectedItems[0].Tag;

            if (!PhoneNumber.Validation(phoneNumber.ID, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }
            phoneNumber = PhoneNumber.Get(phoneNumber.ID, myConnection);

            #endregion

            DialogResult messageResult =
                DataValidationMesaage.ConfirmDeleteData(lstPhoneNumber.SelectedItems[0].SubItems[1].Text);

            if (messageResult == DialogResult.Yes)
            {
                if (phoneNumber.Status)
                {
                    #region NextPhoneNumber Casting

                    int nextPhoneNumberIndex = (int.Parse(lstPhoneNumber.SelectedItems[0].Text)) %
                                               lstPhoneNumber.Items.Count;

                    PhoneNumber nextPhoneNumber = (PhoneNumber)lstPhoneNumber.Items[nextPhoneNumberIndex].Tag;

                    if (!PhoneNumber.Validation(nextPhoneNumber.ID, myConnection))
                    {
                        DataValidationMesaage.NoDataInBank();

                        return;
                    }
                    nextPhoneNumber = PhoneNumber.Get(nextPhoneNumber.ID, myConnection);

                    var query = myConnection.PhoneNumbers.Where(a => a.Member == member);

                    foreach (var item in query)
                    {
                        item.Status = false;

                        myConnection.SubmitChanges();
                    }

                    #endregion

                    nextPhoneNumber.Status = true;

                    myConnection.SubmitChanges();
                }
                PhoneNumber.Delete(phoneNumber, myConnection);

                PhoneNumber.ShowListByMember(lstPhoneNumber, FrmMember.MemberProfile, myConnection);

                if (lstPhoneNumber.Items.Count == 1)
                {
                    btnPhoneDelete.Enabled = false;
                }
            }

            txtPhoneNumber.Clear();

            myConnection.Dispose();
        }
Beispiel #2
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (gridMember.SelectedRows.Count == 0)
            {
                DataValidationMesaage.NoSelectedItemFromList(gridMember.Text);

                return;
            }

            DataBaseDataContext myConnection = Setting.DataBase;

            #region Member Casting

            int memeberId = int.Parse(gridMember.SelectedRows[0].Cells[1].Value.ToString());

            if (!Member.Validation(memeberId, myConnection))

            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            Member member = Member.Get(memeberId, myConnection);

            #endregion

            #region PhoneNumber Casting

            string gridPhoneNumber = gridMember.SelectedRows[0].Cells[9].Value.ToString();

            PhoneNumber phoneNumber =
                myConnection.PhoneNumbers.FirstOrDefault(a => a.Number == gridPhoneNumber && a.Member == member);

            if (!PhoneNumber.Validation(phoneNumber.ID, myConnection))

            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            #endregion

            #region SocialNetworkAccount Casting

            string gridSocialAccount = gridMember.SelectedRows[0].Cells[8].Value.ToString();

            SocialNetworkAccount socialNetworkAccount =
                myConnection.SocialNetworkAccounts.FirstOrDefault(
                    a => a.Account == gridSocialAccount && a.Member == member);

            if (!SocialNetworkAccount.Validation(socialNetworkAccount.ID, myConnection))

            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            #endregion

            DialogResult message = DataValidationMesaage.ConfirmDeleteData(member.Code);

            if (message == DialogResult.Yes)
            {
                PhoneNumber.Delete(phoneNumber, myConnection);

                SocialNetworkAccount.Delete(socialNetworkAccount, myConnection);

                Member.Delete(member, myConnection);

                DataValidationMesaage.DeleteMessage();

                GetCode();

                Member.LoadGridJoinSocialNetworkAccountJoinPhoneNumber(gridMember, myConnection);
            }
        }