Beispiel #1
0
        private void BtnSave_Click(object sender, RoutedEventArgs e)
        {
            var x = this.DataContext as Orphan;

            if (x.IsValidate())
            {
                if (x.OrphanID.HasValue)
                {
                    if (Orphan.UpdateData(x))
                    {
                        MyMessage.UpdateMessage();
                        DialogResult = true;
                    }
                }
                else
                {
                    DialogResult = true;
                }
            }
        }
        public void btnSave_Click(object sender, RoutedEventArgs e)
        {
            var x = this.DataContext as Orphan;

            if (x.IsValidate())
            {
                if (x.OrphanFamily.FamilyID == null)
                {
                    MyMessageBox.Show("لم يتم إدخال بيانات العائلة");
                    return;
                }

                if (x.OrphanFamily.FamilyType == "أيتام")
                {
                    if (x.Gender == "ذكر" && (((BaseDataBase.DateNow - x.DOB.Value)).Days / 30 / 12) >= 14)
                    {
                        if (MyMessageBox.Show("عمر اليتيم أكبر من 14\nهل تريد المتابعة", MessageBoxButton.YesNo) != MessageBoxResult.Yes)
                        {
                            return;
                        }
                    }
                }

                if (x.OrphanID != null)
                {
                    if (Orphan.UpdateData(x))
                    {
                        MyMessage.UpdateMessage();
                    }
                }
                else
                {
                    if (Orphan.InsertData(x))
                    {
                        MyMessage.InsertMessage();
                    }
                }
            }
        }
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            var f = cOrphanFamily.DataContext as Family;

            if (f.IsValidate())
            {
                if (!(string.IsNullOrEmpty(f.FamilyFather.FirstName) && string.IsNullOrEmpty(f.FamilyFather.LastName)))
                {
                    if (!f.FamilyFather.IsValidate())
                    {
                        return;
                    }
                }
                if (!(string.IsNullOrEmpty(f.FamilyMother.FirstName) && string.IsNullOrEmpty(f.FamilyMother.LastName)))
                {
                    if (!f.FamilyMother.IsValidate())
                    {
                        return;
                    }
                }
                if (!(string.IsNullOrEmpty(f.OrphanGuardian.FirstName) && string.IsNullOrEmpty(f.OrphanGuardian.LastName)))
                {
                    if (!f.OrphanGuardian.IsValidate())
                    {
                        return;
                    }
                }
                if (!(string.IsNullOrEmpty(f.OrphanNursemaid.FirstName) && string.IsNullOrEmpty(f.OrphanNursemaid.LastName)))
                {
                    if (!f.OrphanNursemaid.IsValidate())
                    {
                        return;
                    }
                }
                if (!string.IsNullOrEmpty(f.FamilyHouse.OldAddress) || !string.IsNullOrEmpty(f.FamilyHouse.Address))
                {
                    if (!f.FamilyHouse.IsValidate())
                    {
                        return;
                    }
                }
                foreach (var fp in cOrphanFamily.dgChild.ItemsSource as List <FamilyPerson> )
                {
                    if (!fp.IsValidate())
                    {
                        return;
                    }
                }

                if (cOrphanFamily.Orphans == null || cOrphanFamily.Orphans.Count == 0)
                {
                    MyMessageBox.Show("يجب ادخال بيانات الايتام");
                    return;
                }

                if (!f.FamilyID.HasValue)
                {
                    if (!DBMain.InsertData(f))
                    {
                        return;
                    }
                    else
                    {
                        MyMessage.InsertMessage();
                        var tih = this.Parent as TabItem;
                        if (tih != null)
                        {
                            tih.Header = f.FamilyCode + " " + f.FamilyName;
                        }
                    }
                }
                else if (!DBMain.UpdateData(f))
                {
                    return;
                }
                else
                {
                    MyMessage.UpdateMessage();
                }

                //Father
                if (!(string.IsNullOrEmpty(f.FamilyFather.FirstName) && string.IsNullOrEmpty(f.FamilyFather.LastName)))
                {
                    if (f.FamilyFather.ParentrID.HasValue)
                    {
                        DBMain.UpdateData(f.FamilyFather);
                    }
                    else
                    {
                        DBMain.InsertData(f.FamilyFather);
                    }
                }
                else if (f.FamilyFather.ParentrID.HasValue)
                {
                    DBMain.DeleteData(f.FamilyFather);
                }
                //Mother
                if (!(string.IsNullOrEmpty(f.FamilyMother.FirstName) && string.IsNullOrEmpty(f.FamilyMother.LastName)))
                {
                    if (f.FamilyMother.ParentrID.HasValue)
                    {
                        DBMain.UpdateData(f.FamilyMother);
                    }
                    else
                    {
                        DBMain.InsertData(f.FamilyMother);
                    }
                }
                else if (f.FamilyMother.ParentrID.HasValue)
                {
                    DBMain.DeleteData(f.FamilyMother);
                }
                //Guardian
                if (!(string.IsNullOrEmpty(f.OrphanGuardian.FirstName) && string.IsNullOrEmpty(f.OrphanGuardian.LastName)))
                {
                    f.OrphanGuardian.FamilyID = f.FamilyID;
                    if (f.OrphanGuardian.GuardianID.HasValue)
                    {
                        Guardian.UpdateData(f.OrphanGuardian);
                    }
                    else
                    {
                        Guardian.InsertData(f.OrphanGuardian);
                    }
                }
                else if (f.OrphanGuardian.GuardianID.HasValue)
                {
                    Guardian.DeleteData(f.OrphanGuardian);
                }
                //Nursemaid
                if (!(string.IsNullOrEmpty(f.OrphanNursemaid.FirstName) && string.IsNullOrEmpty(f.OrphanNursemaid.LastName)))
                {
                    f.OrphanNursemaid.FamilyID = f.FamilyID;
                    if (f.OrphanNursemaid.GuardianID.HasValue)
                    {
                        Guardian.UpdateData(f.OrphanNursemaid);
                    }
                    else
                    {
                        Guardian.InsertData(f.OrphanNursemaid);
                    }
                }
                else if (f.OrphanNursemaid.GuardianID.HasValue)
                {
                    Guardian.DeleteData(f.OrphanNursemaid);
                }

                f.FamilyHouse.FamilyID = f.FamilyID;
                if (!string.IsNullOrEmpty(f.FamilyHouse.OldAddress) || !string.IsNullOrEmpty(f.FamilyHouse.HouseSection))
                {
                    if (f.FamilyHouse.HouseID == null)
                    {
                        DBMain.InsertData(f.FamilyHouse);
                    }
                    else
                    {
                        DBMain.UpdateData(f.FamilyHouse);
                    }
                }

                foreach (var fp in cOrphanFamily.dgChild.ItemsSource as List <FamilyPerson> )
                {
                    if (fp.FamilyPersonID.HasValue)
                    {
                        DBMain.UpdateData(fp);
                    }
                    else if (f.FamilyID.HasValue)
                    {
                        fp.FamilyID = f.FamilyID;
                        DBMain.InsertData(fp);
                    }
                }
                foreach (var o in cOrphanFamily.Orphans)
                {
                    if (o.OrphanID.HasValue)
                    {
                        Orphan.UpdateData(o);
                    }
                    else if (f.FamilyID.HasValue)
                    {
                        if (Orphan.InsertData(o))
                        {
                            o.Account                = new Account();
                            o.Account.Name           = o.FirstName + " " + o.LastName;
                            o.Account.Type           = o.Type == "يتيم" ? Account.AccountType.Orphan : o.Type == "يتيم طالب علم" ? Account.AccountType.OrphanStudent : Account.AccountType.Student;
                            o.Account.CurrentBalance = 0;
                            o.Account.CreateDate     = BaseDataBase.DateNow;
                            o.Account.OwnerID        = o.OrphanID;
                            o.Account.Status         = "مفعل";
                            o.Account.IsDebit        = true;

                            Account.InsertData(o.Account);
                        }
                    }
                }
                cFamilyNeed.FamilyID            = f.FamilyID;
                cExternalFamilySupport.FamilyID = f.FamilyID;
                cSpecialCard.FamilyID           = f.FamilyID;
                cListerGroup.FamilyID           = f.FamilyID;
                cOrders.FamilyID = f.FamilyID;

                f.UpdateFamilyPersonCount();
            }
        }