예제 #1
0
        public static List <Guardian> GetAllGuardian()
        {
            List <Guardian> xx  = new List <Guardian>();
            SqlConnection   con = new SqlConnection(BaseDataBase.ConnectionString);
            SqlCommand      com = new SqlCommand("sp_Get_All_Guardian", con);

            com.CommandType = System.Data.CommandType.StoredProcedure;
            try
            {
                con.Open();
                SqlDataReader rd = com.ExecuteReader();
                while (rd.Read())
                {
                    Guardian x = new Guardian();

                    if (!(rd["GuardianID"] is DBNull))
                    {
                        x.GuardianID = int.Parse(rd["GuardianID"].ToString());
                    }
                    x.FirstName    = rd["FirstName"].ToString();
                    x.LastName     = rd["LastName"].ToString();
                    x.FatherName   = rd["FatherName"].ToString();
                    x.Relationship = rd["Relationship"].ToString();
                    x.Gender       = rd["Gender"].ToString();
                    if (!(rd["DOB"] is DBNull))
                    {
                        x.DOB = DateTime.Parse(rd["DOB"].ToString());
                    }
                    x.Job           = rd["Job"].ToString();
                    x.Phone         = rd["Phone"].ToString();
                    x.Mobile        = rd["Mobile"].ToString();
                    x.Email         = rd["Email"].ToString();
                    x.MaritalStatus = rd["MaritalStatus"].ToString();
                    x.Notes         = rd["Notes"].ToString();
                    x.PID           = rd["PID"].ToString();
                    if (!(rd["FamilyID"] is DBNull))
                    {
                        x.FamilyID = int.Parse(rd["FamilyID"].ToString());
                    }
                    xx.Add(x);
                }
                rd.Close();
            }
            catch
            {
                xx = null;
            }
            finally
            {
                con.Close();
            }
            return(xx);
        }
예제 #2
0
 public static bool UpdateData(Guardian x)
 {
     return(BaseDataBase._StoredProcedure("sp_Update_Guardian"
                                          , new SqlParameter("@GuardianID", x.GuardianID)
                                          , new SqlParameter("@FirstName", x.FirstName)
                                          , new SqlParameter("@LastName", x.LastName)
                                          , new SqlParameter("@FatherName", x.FatherName)
                                          , new SqlParameter("@Gender", x.Gender)
                                          , new SqlParameter("@DOB", x.DOB)
                                          , new SqlParameter("@Job", x.Job)
                                          , new SqlParameter("@Phone", x.Phone)
                                          , new SqlParameter("@Mobile", x.Mobile)
                                          , new SqlParameter("@Email", x.Email)
                                          , new SqlParameter("@MaritalStatus", x.MaritalStatus)
                                          , new SqlParameter("@Notes", x.Notes)
                                          , new SqlParameter("@Relationship", x.Relationship)
                                          , new SqlParameter("@PID", x.PID)
                                          , new SqlParameter("@FamilyID", x.FamilyID)));
 }
예제 #3
0
 public static bool InsertData(Guardian x)
 {
     x.GuardianID = BaseDataBase._StoredProcedureReturnable("sp_Add_Guardian"
                                                            , new SqlParameter("@GuardianID", SqlDbType.Int)
                                                            , new SqlParameter("@FirstName", x.FirstName)
                                                            , new SqlParameter("@LastName", x.LastName)
                                                            , new SqlParameter("@FatherName", x.FatherName)
                                                            , new SqlParameter("@Gender", x.Gender)
                                                            , new SqlParameter("@DOB", x.DOB)
                                                            , new SqlParameter("@Job", x.Job)
                                                            , new SqlParameter("@Phone", x.Phone)
                                                            , new SqlParameter("@Mobile", x.Mobile)
                                                            , new SqlParameter("@Email", x.Email)
                                                            , new SqlParameter("@MaritalStatus", x.MaritalStatus)
                                                            , new SqlParameter("@Notes", x.Notes)
                                                            , new SqlParameter("@Relationship", x.Relationship)
                                                            , new SqlParameter("@PID", x.PID)
                                                            , new SqlParameter("@FamilyID", x.FamilyID));
     return(x.GuardianID.HasValue);
 }
        async void FillData(Orphan o)
        {
            Family f  = o.OrphanFamily;
            var    hs = House.GetHouseAllByFamilyID(f.FamilyID);

            if (hs != null && hs.Count() > 0)
            {
                f.FamilyHouse = hs.Last();
            }
            else
            {
                f.FamilyHouse = new House();
            }

            if (f.FamilyID.HasValue)
            {
                cOrphanFamily.dgChild.ItemsSource = (from x in FamilyPerson.GetFamilyPersonByFamilyID(f.FamilyID.Value) orderby x.DOB select x).ToList();
            }
            else
            {
                cOrphanFamily.dgChild.ItemsSource = new List <FamilyPerson>();
            }

            cFamilyNeed.FamilyID            = f.FamilyID;
            cExternalFamilySupport.FamilyID = f.FamilyID;
            cSpecialCard.FamilyID           = f.FamilyID;
            cListerGroup.FamilyID           = f.FamilyID;
            cTrainings.FamilyID             = f.FamilyID;

            if (o.OrphanID.HasValue)
            {
                cSponsor.OrphanID = o.OrphanID;
            }
            cOrders.FamilyID = f.FamilyID;
            cOrphanFamily.txtFamilyCode.IsReadOnly = true;

            if (o.OrphanID.HasValue)
            {
                o.Account        = Account.GetAccountByOwnerID(Account.AccountType.Student, o.OrphanID.Value);
                cAccount.Account = o.Account;
            }
            Guardian.GetAllGuardianByFamily(f);
            if (f.OrphanNursemaid == null)
            {
                f.OrphanNursemaid = new Guardian()
                {
                    Gender = "أنثى"
                }
            }
            ;
            if (f.OrphanGuardian == null)
            {
                f.OrphanGuardian = new Guardian()
                {
                    Gender = "ذكر"
                }
            }
            ;

            f.FamilyOrphans = await Orphan.GetAllOrphanByFamily(f, o, true);

            cOrphanFamily.Orphans = await Orphan.GetAllOrphanByFamily(f, o);
        }
        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();
            }
        }
예제 #6
0
 public static bool DeleteData(Guardian x)
 {
     return(BaseDataBase._StoredProcedure("sp_Delete_Guardian"
                                          , new SqlParameter("@GuardianID", x.GuardianID)));
 }