Beispiel #1
0
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            if (!BaseDataBase.CurrentUser.CanUpdateFamily)
            {
                MyMessageBox.Show("ليس لديك صلاحية تعديل بيانات عائلة");
                return;
            }
            MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            var f = cFamily.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.FamilyHouse.OldAddress) || !string.IsNullOrEmpty(f.FamilyHouse.Address))
                {
                    if (!f.FamilyHouse.IsValidate())
                    {
                        return;
                    }
                }
                foreach (var fp in cFamily.dgChild.ItemsSource as List <FamilyPerson> )
                {
                    if (!fp.IsValidate())
                    {
                        return;
                    }
                }

                if (DBMain.UpdateData(f))
                {
                    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);
                    }

                    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);
                    }

                    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 cFamily.dgChild.ItemsSource as List <FamilyPerson> )
                    {
                        if (!fp.FamilyPersonID.HasValue)
                        {
                            fp.FamilyID = f.FamilyID;
                            DBMain.InsertData(fp);
                        }
                        else
                        {
                            DBMain.UpdateData(fp);
                        }
                    }
                    f.UpdateFamilyPersonCount();
                    MyMessage.UpdateMessage();
                }
            }
        }
Beispiel #2
0
        private void btnExecute_Click(object sender, RoutedEventArgs e)
        {
            MoveFocus(new TraversalRequest(FocusNavigationDirection.Next));
            var f = cFamily.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.FamilyHouse.OldAddress) || !string.IsNullOrEmpty(f.FamilyHouse.Address))
                {
                    if (!f.FamilyHouse.IsValidate())
                    {
                        return;
                    }
                }
                foreach (var fp in cFamily.dgChild.ItemsSource as List <FamilyPerson> )
                {
                    if (!fp.IsValidate())
                    {
                        return;
                    }
                }


                string a = (cFamily.cmboSector.SelectedItem as Sector).Code;
                string s = a + BaseDataBase._Scalar_StoredProcedure("sp_GetMaxFamilyCodeByChar", new SqlParameter("@char", a));
                f.FamilyCode = s;

                if (DBMain.InsertData(f))
                {
                    var tih = this.Parent as TabItem;
                    if (tih != null)
                    {
                        tih.Header = f.FamilyCode + " " + f.FamilyName;
                    }

                    if (tf != null)
                    {
                        tf.FamilyID = f.FamilyID;
                        TempFamily.UpadteData(tf);
                    }
                    if (!(string.IsNullOrEmpty(f.FamilyFather.FirstName) && string.IsNullOrEmpty(f.FamilyFather.LastName)))
                    {
                        DBMain.InsertData(f.FamilyFather);
                    }

                    if (!(string.IsNullOrEmpty(f.FamilyMother.FirstName) && string.IsNullOrEmpty(f.FamilyMother.LastName)))
                    {
                        DBMain.InsertData(f.FamilyMother);
                    }

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

                    foreach (var fp in cFamily.dgChild.ItemsSource as List <FamilyPerson> )
                    {
                        if (f.FamilyID.HasValue && !fp.FamilyPersonID.HasValue)
                        {
                            fp.FamilyID = f.FamilyID;
                            DBMain.InsertData(fp);
                        }
                    }

                    btnUpdate.Visibility  = System.Windows.Visibility.Visible;
                    btnExecute.Visibility = System.Windows.Visibility.Collapsed;

                    cFamilyNeed.FamilyID            = f.FamilyID;
                    cExternalFamilySupport.FamilyID = f.FamilyID;
                    cSpecialCard.FamilyID           = f.FamilyID;
                    cListerGroup.FamilyID           = f.FamilyID;
                    cAdminEvaluation.FamilyID       = f.FamilyID;
                    cOrders.FamilyID = f.FamilyID;

                    f.UpdateFamilyPersonCount();
                    EnableTabs();
                    MyMessage.InsertMessage();
                }
            }
        }