private void btnSave_Click(object sender, EventArgs e)
        {
            if (radioGroupType.SelectedIndex == 1 && dedateend.EditValue == null)
            {
                Program.ShowMsg("يجب ادخال تاريخ انتهاء الؤقت", false, this, true);
                return;
            }
            if (ceestefaa.Checked && tbKideNumber.Text != string.Empty)
            {
                Program.Logger.LogThis("لا يمكن حفظ استيفاء ألا بعد حذف رقم القيد", Text, FXFW.Logger.OpType.fail, null, null, this);
                return;
            }
            if (_row.estefaa == true && !_row.IsKideNumberNull())
            {
                Program.Logger.LogThis("لا يمكن حفظ استيفاء ألا بعد حذف رقم القيد", Text, FXFW.Logger.OpType.success, null, null, this);
                return;
            }
            if (lueSyndicateId.EditValue != null)
                _row.SyndicateId = Convert.ToInt32(lueSyndicateId.EditValue);
            if (lueSubCommitteId.EditValue != null)
                _row.SubCommitteId = Convert.ToInt32(lueSubCommitteId.EditValue);
            if (tbMemberName.EditValue != null)
                _row.MemberName = Convert.ToString(tbMemberName.EditValue);
            if (deBirthDate.EditValue != null)
                _row.BirthDate = Convert.ToDateTime(deBirthDate.EditValue);
            if (lueQualtypeId.EditValue != null)
                _row.QualtypeId = Convert.ToByte(lueQualtypeId.EditValue);
            if (lueJobtitleID.EditValue != null)
                _row.JobtitleID = Convert.ToInt32(lueJobtitleID.EditValue);
            if (luemembertypeid.EditValue != null)
                _row.membertypeid = Convert.ToByte(luemembertypeid.EditValue);
            if (deWorkeDate.EditValue != null)
                _row.WorkeDate = Convert.ToDateTime(deWorkeDate.EditValue);
            if (dekasmDate.EditValue != null)
                 _row.kasmDate = Convert.ToDateTime(dekasmDate.EditValue);
            if (ceclosed.EditValue != null)
                _row.closed = Convert.ToBoolean(ceclosed.EditValue);
            if (ceestefaa.EditValue != null)
                _row.estefaa = Convert.ToBoolean(ceestefaa.EditValue);
            if (cerekeed.EditValue != null)
                _row.rekeed = Convert.ToBoolean(cerekeed.EditValue);

            //if (Misc.Misc.CalcAge(_row.BirthDate) >= 45 && _row.NewMember)
            //{
            //    //Program.Logger.LogThis("لا يجب ادخال عضو اكبر من 45 سنة", Text, FXFW.Logger.OpType.fail, null, null, this);
            //    if (MessageBox.Show("هذا العضو اكبر من 45 سنه هل ترغب في حفظ العضو كعضو قديم؟", "عضو جديد غير لائق", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
            //        return;
            //    else
            //        _row.NewMember = false;
            //}

            //
            if (tbestefareson.EditValue != null)
            {
                if (tbestefareson.EditValue.ToString() == string.Empty && FXFW.SqlDB.UserInfo.UserID != "1")
                    Program.Logger.LogThis("سوف يتم الحفظ لكن لن يتم مسح سبب الاستيفاء", Text, FXFW.Logger.OpType.success, null, null, this);
                else
                    _row.estefareson = Convert.ToString(tbestefareson.EditValue);
            }
            if (tbmnid.EditValue != null)
                _row.mnid = tbmnid.EditValue.ToString();
            if (deestefadate.EditValue != null)
                _row.estefadate = Convert.ToDateTime(deestefadate.EditValue);
            if (dereternestefadate.EditValue != null)
                _row.reternestefadate = Convert.ToDateTime(dereternestefadate.EditValue);
            if (tbesalno.EditValue != null && tbesalno.EditValue.ToString() != string.Empty)
                _row.esalno = Convert.ToInt32(tbesalno.EditValue);
            else
                _row.SetesalnoNull();
            if (tbKideNumber.EditValue != null && tbKideNumber.EditValue.ToString() != string.Empty)
            {
                int KideNumber = Convert.ToInt32(tbKideNumber.EditValue);
                DataSources.dsTeachersUnionTableAdapters.TBLMembersTableAdapter adpMem = new DataSources.dsTeachersUnionTableAdapters.TBLMembersTableAdapter();
                DataSources.dsTeachersUnionTableAdapters.TBLMemberWebTableAdapter adpMemWeb = new DataSources.dsTeachersUnionTableAdapters.TBLMemberWebTableAdapter();
                if (_row.RowState == DataRowState.Detached)
                {
                    if (adpMem.ScalarQueryExistsKideNumber(KideNumber) != 0 || adpMemWeb.ScalarQueryExistsKideNumber(_row.MemberId, KideNumber) != 0)
                    {
                        Program.ShowMsg("رقم القيد موجود مسبقا", true, this);
                        Program.Logger.LogThis("رقم القيد موجود مسبقا", Text, FXFW.Logger.OpType.warning, null, null, this);
                        return;
                    }
                }
                else
                {
                    int memberid = 0;
                    if (_row.closed)
                        memberid = (int)adpMem.ScalarQueryKideNumberByMemberId(_row.KideNumber);
                    if (adpMem.ScalarQueryExistsKideNumber_MemberId(KideNumber, memberid) != 0 || adpMemWeb.ScalarQueryExistsKideNumber(_row.MemberId, KideNumber) != 0)
                    {
                        Program.ShowMsg("رقم القيد موجود مسبقا", true, this);
                        Program.Logger.LogThis("رقم القيد موجود مسبقا", Text, FXFW.Logger.OpType.warning, null, null, this);
                        return;
                    }
                }
                
                _row.KideNumber = KideNumber;
            }
            else
                _row.SetKideNumberNull();

            if (radioGroupType.SelectedIndex == 0)
            {
                _row.CardtypeId = 1;
            }
            else if (radioGroupType.SelectedIndex == 1)
            {
                _row.CardtypeId = 2;
                _row.dateend = dedateend.DateTime;
                _row.Installment = ceInstallment.Checked;
            }
            if (ImageChanged)// if user pick another image
            {
                System.IO.MemoryStream ms = new System.IO.MemoryStream();
                if (peimagepath.Image != null)
                {
                    peimagepath.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    peimagepath.Image.Dispose(); peimagepath.Image = null;
                }
                if (!_row.IsimagepathNull() && _row.imagepath != string.Empty)
                {
                    if (System.IO.File.Exists(Program.imgPathWeb + _row.imagepath))
                        System.IO.File.Delete(Program.imgPathWeb + _row.imagepath);
                }
                if (ms.Length > 0)
                {
                    string fileName = string.Format("{0}{1}{2}{3}{4}{5}{6}.jpg", DateTime.Now.Year, DateTime.Now.Month,
                        DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second, DateTime.Now.Millisecond);
                    Image.FromStream(ms).Save(Program.imgPathWeb + fileName);
                    ms.Close();
                    _row.imagepath = fileName;
                }
            }

            if (tbKideNumber.Properties.Buttons[0].Kind == DevExpress.XtraEditors.Controls.ButtonPredefines.Plus)
                _row.kednew = true;
            else
                _row.kednew = false;

            _row.userin = Program.UserInfo.UserId;
            _row.datein = SQLProvider.GetServerDateTime();

            if (!_row.IsKideNumberNull() && _KideNumber != _row.KideNumber)
                _row.userked = _row.userin;

            if (!_row.IsesalnoNull())
            {

                if (_row["esalno", DataRowVersion.Current].ToString() != _row["esalno", DataRowVersion.Original].ToString())
                {
                    if (Convert.ToInt32(SQLProvider.adpQry.eslanoRemains(_row.esalno)) - 1 < 0)
                    {
                        Program.Logger.LogThis("هذا الايصال تم ادخال كل اعضائة", Text, FXFW.Logger.OpType.fail, null, null, this);
                        return;
                    }
                }
            }

            DialogResult = System.Windows.Forms.DialogResult.OK;

        }
        private void repositoryItemButtonEditEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            GridView GV = (GridView)gridControlData.MainView;
            DataSources.dsTeachersUnion.TBLMemberWebRow row = (DataSources.dsTeachersUnion.TBLMemberWebRow)GV.GetFocusedDataRow();
            if (!row.IsclosedNull() && row.closed && !Program.UserInfo.IsAdmin)
            {
                Program.ShowMsg("لا يمكن تعديل حقل مغلق", true, this);
                Program.Logger.LogThis("لا يمكن تعديل حقل مغلق", Text, FXFW.Logger.OpType.information, null, null, this);
                dsTeachersUnionList.TBLMemberWeb.RejectChanges();
                return;
            }
            tblMemberWebBindingSource.EndEdit();
            if (row.IsCardtypeIdNull() || (!row.rekeed && !row.estefaa))
            {
                Program.ShowMsg("بيانات فارغة يجب ادخالها", true, this);
                Program.Logger.LogThis("بيانات فارغة يجب ادخالها", Text, FXFW.Logger.OpType.information, null, null, this);
                return;
            }
            if (row.rekeed && row.estefaa)
            {
                Program.ShowMsg("لا يجب ان يكون العضو استيفاء ومراجعة قيد", true, this);
                Program.Logger.LogThis("لا يجب ان يكون العضو استيفاء ومراجعة قيد", Text, FXFW.Logger.OpType.information, null, null, this);
                return;
            }

            if (!row.IsesalnoNull())
            {
                if (row["esalno", DataRowVersion.Current].ToString() != row["esalno", DataRowVersion.Original].ToString())
                {
                    if (Convert.ToInt32(SQLProvider.adpQry.eslanoRemains(row.esalno)) - 1 < 0)
                    {
                        Program.Logger.LogThis("هذا الايصال تم ادخال كل اعضائة", Text, FXFW.Logger.OpType.fail, null, null, this);
                        return;
                    }
                }
            }
            if (!row.IsKideNumberNull() && row.KideNumber != 0)
            {
                if (row.estefaa)
                {
                    Program.Logger.LogThis("لا يمكن حفظ استيفاء ألا بعد حذف رقم القيد", Text, FXFW.Logger.OpType.fail, null, null, this);
                    return;
                }
                int KideNumber = row.KideNumber;
                DataSources.dsTeachersUnionTableAdapters.TBLMembersTableAdapter adpMem = new DataSources.dsTeachersUnionTableAdapters.TBLMembersTableAdapter();
                DataSources.dsTeachersUnionTableAdapters.TBLMemberWebTableAdapter adpMemWeb = new DataSources.dsTeachersUnionTableAdapters.TBLMemberWebTableAdapter();
                if (adpMem.ScalarQueryExistsKideNumber(KideNumber) != 0 || adpMemWeb.ScalarQueryExistsKideNumber(row.MemberId, KideNumber) != 0)
                {
                    Program.ShowMsg("رقم القيد موجود مسبقا", true, this);
                    Program.Logger.LogThis("رقم القيد موجود مسبقا", Text, FXFW.Logger.OpType.warning, null, null, this);
                    return;
                }
            }
            try
            {
                if (!row.IsInstallmentNull() && row.Installment)
                {
                    int index = CheckAksatRowExists(row.MemberId);
                    if (index == -1)
                    {
                        Program.Logger.LogThis("يجب مليء تفاصيل التقسيط", Text, FXFW.Logger.OpType.fail, null, null, this);
                        return;
                    }
                    DataSources.dsTeachersUnion.TBLAksatWEBRow KstRow = (DataSources.dsTeachersUnion.TBLAksatWEBRow)dsTeachersUnionList.TBLAksatWEB[index];
                    if (KstRow.IsNull("kestenddate") || KstRow.IsNull("mostahk") || KstRow.IsNull("madfoaa") || KstRow.IsNull("esalno") || KstRow.IsNull("esaldate"))
                    {
                        Program.Logger.LogThis("تفاصيل التقسيط غير مكتملة", Text, FXFW.Logger.OpType.fail, null, null, this);
                        return;
                    }
                }
                row.datein = SQLProvider.GetServerDateTime();
                row.userin = Program.UserInfo.UserId;
                tblMemberWebBindingSource.EndEdit();
                tblMemberWebTableAdapter.Update(row);
                dsTeachersUnionList.TBLMemberWeb.AcceptChanges();
                if (!row.IsInstallmentNull() && row.Installment)
                {
                    tblAksatWEBTableAdapter.Update(dsTeachersUnionList.TBLAksatWEB[CheckAksatRowExists(row.MemberId)]);
                    dsTeachersUnionList.TBLAksatWEB.AcceptChanges();
                }

                Program.ShowMsg("تم الحفظ", false, this);
                Program.Logger.LogThis("تم الحفظ", Text, FXFW.Logger.OpType.success, null, null, this);
            }
            catch (Exception ex)
            {
                Program.ShowMsg(Misc.Misc.ExceptionMessage(ex), true, this);
                Program.Logger.LogThis(null, Text, FXFW.Logger.OpType.fail, ex, null, this);
            }
        }