コード例 #1
0
        private void btnPhoneEdit_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 message = MessageBox.Show("در صورت تایید شماره تماس فعلی فعال گردیده و مابقی غیرفعال میگردند",
                                                   "کاربر گرامی", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

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

                    return;
                }


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

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

                    myConnection.SubmitChanges();
                }

                PhoneNumber.Edit(phoneNumber, phone, member, true, txtPhoneNumber.Text, myConnection);

                txtPhoneNumber.Clear();

                PhoneNumber.ShowListByMember(lstPhoneNumber, member, myConnection);
            }

            myConnection.Dispose();
        }
コード例 #2
0
        private void btnYes_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtFirstName.Text) || string.IsNullOrEmpty(txtLastName.Text) ||
                string.IsNullOrEmpty(txtNationalCode.Text) ||
                string.IsNullOrWhiteSpace(txtFirstName.Text) || string.IsNullOrWhiteSpace(txtLastName.Text) ||
                string.IsNullOrWhiteSpace(txtNationalCode.Text))
            {
                MessageBox.Show("کاربر گرامی مقادیر نام یا نام خانوادگی یا کد ملی نمی توانند خالی باشند ", "اخطار در ورود اطلاعات", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return;
            }

            DataBaseDataContext myConnection = Setting.DataBase;

            #region Level Casting

            int levelId = ((Level)cmbLevel.SelectedItem).ID;

            if (!Level.Validation(levelId, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            Level level = Level.Get(levelId, myConnection);

            #endregion

            #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 != null && !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 != null && !SocialNetworkAccount.Validation(socialNetworkAccount.ID, myConnection))

            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

            #endregion

            #region Phone Casting

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

            if (!Phone.Validation(phoneId, myConnection))
            {
                //TODO Fix Message

                DataValidationMesaage.NoDataInBank();

                return;
            }

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

            #endregion

            #region SocialNetwork Casting

            int socialNetworkTypeID = ((SocialNetworkType)cmbSocialNetworkType.SelectedItem).ID;

            if (!Phone.Validation(socialNetworkTypeID, myConnection))
            {
                //TODO Fix Message

                DataValidationMesaage.NoDataInBank();

                return;
            }

            SocialNetworkType socialNetworkType = SocialNetworkType.Get(socialNetworkTypeID, myConnection);

            #endregion

            bool query = myConnection.PhoneNumbers.Any(a => a.Number == CorrectPhoneNumber() &&
                                                       a.Member == member && a.ID != phoneNumber.ID);
            if (query)
            {
                DataValidationMesaage.DuplicateData("شماره تماس برای این کاربر");

                return;
            }

            query =
                myConnection.SocialNetworkAccounts.Any(
                    a =>
                    a.Account == txtSocialAccount.Text.Trim() && a.Member == member &&
                    a.ID != socialNetworkAccount.ID);

            if (query)
            {
                DataValidationMesaage.DuplicateData("اکانت شبکه های اجتماعی برای این کاربر");

                return;
            }

            query = myConnection.Members.Any(a => a.NationalCode == txtNationalCode.Text.Trim() && a.ID != memeberId);

            if (query)
            {
                DataValidationMesaage.DuplicateData("کاربر با این کد ملی");

                return;
            }

            if (!flag)
            {
                Image picImage = Properties.Resources.profile;

                picBox.Image = picImage;

                picImage.Save(_memory, picBox.Image.RawFormat);

                _myArray = _memory.GetBuffer();
            }

            if (flag)
            {
                _image.Save(_memory, picBox.Image.RawFormat);

                _myArray = _memory.GetBuffer();
            }


            Phone.Edit(phone, cmbPhone.Text.Trim(), myConnection);

            PhoneNumber.Edit(phoneNumber, phone, member, true, CorrectPhoneNumber(), myConnection);

            SocialNetworkType.Edit(socialNetworkType, cmbSocialNetworkType.Text.Trim(), myConnection);

            SocialNetworkAccount.Edit(socialNetworkAccount, socialNetworkType, member, true, txtSocialAccount.Text.Trim(), myConnection);

            //TODO How to check Has Cabinet or not?

            Member.Edit(member, txtCode.Text.Trim(), txtFirstName.Text.Trim(), txtLastName.Text.Trim(),
                        txtNationalCode.Text.Trim(), BTM.Date.ConvertToGorgianDate(txtBirthDate.Text.Trim()),
                        cmbType.Text.Trim(), cmbSex.Text.Trim(), _myArray, level, myConnection);

            DataValidationMesaage.EditMessage();

            ClearTextBox();

            txtFirstName.Focus();

            Member.LoadGridJoinSocialNetworkAccountJoinPhoneNumber(gridMember, myConnection);

            FormManagement.DisableYesNo(this.Controls);
        }