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

            if (string.IsNullOrWhiteSpace(txtSocialAccount.Text) || string.IsNullOrEmpty(txtSocialAccount.Text))
            {
                DataValidationMesaage.BlankTextBox("اکانت شبکه های اجتماعی");

                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 SocialNetworkType Casting

            int socialNetworkTypeId = ((SocialNetworkType)cmbSocialAccount.SelectedItem).ID;

            if (!SocialNetworkType.Validation(socialNetworkTypeId, myConnection))
            {
                DataValidationMesaage.NoDataInBank();

                return;
            }

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

            #endregion

            if (myConnection.SocialNetworkAccounts.Any(
                    a => a.Account == txtSocialAccount.Text.Trim() && a.Member == member &&
                    a.SocialNetworkType == socialNetworkType))
            {
                DataValidationMesaage.DuplicateData(txtSocialAccount.Text.Trim());

                return;
            }

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

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

                myConnection.SubmitChanges();
            }



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

            DataValidationMesaage.AcceptMessage(socialNetworkAccount.Account);

            SocialNetworkAccount.ShowListByMember(lstSocialNetwork, member, myConnection);

            txtSocialAccount.Clear();

            if (lstSocialNetwork.Items.Count > 1)
            {
                btnSocialAccountDelete.Enabled = true;
            }

            myConnection.Dispose();
        }
示例#2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            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 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 Save Image

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

                picBox.Image = picImage;

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

                _myArray = _memoryStream.GetBuffer();
            }

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

                _myArray = _memoryStream.GetBuffer();
            }

            #endregion

            if (myConnection.Members.Any(a => a.Code == txtCode.Text))
            {
                DataValidationMesaage.DuplicateData(txtCode.Text);

                return;
            }

            if (myConnection.Members.Any(a => a.NationalCode == txtNationalCode.Text))
            {
                DataValidationMesaage.DuplicateData(txtNationalCode.Text);

                return;
            }

            if (string.IsNullOrEmpty(txtNationalCode.Text.Trim()) || string.IsNullOrWhiteSpace(txtNationalCode.Text.Trim()))
            {
                DataValidationMesaage.BlankTextBox("کد ملی");

                return;
            }

            if (!BTM.Date.Validation(txtBirthDate.Text))
            {
                MessageBox.Show("قالب تاریخ تولد وارد شده صحیح نمی باشد", "اخطار در ورود اطلاعات", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);

                return;
            }


            Member member = Member.Insert(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, false, level, myConnection);

            PhoneNumber.Insert(phone, member, true, CorrectPhoneNumber(), myConnection);


            if (txtSocialAccount.Text.Length > 0)
            {
                #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

                SocialNetworkAccount.Insert(socialNetworkType, member, true, txtSocialAccount.Text.Trim(), myConnection);
            }
            GetCode();

            Member.LoadGridJoinSocialNetworkAccountJoinPhoneNumber(gridMember, myConnection);

            ClearTextBox();

            myConnection.Dispose();
        }