예제 #1
0
        public static bool ImportAllActiveStaff(Guid SchoolYearId, Guid SchoolId, Guid OldCurrentSchoolYearId, System.Data.Common.DbTransaction tran, DayCareDataContext dbold)
        {
            DayCarePL.Logger.Write(DayCarePL.LogType.INFO, DayCarePL.ModuleToLog.clStaffSchoolYear, "ImportAllActiveStaff", "Execute ImportAllActiveStaff Method", DayCarePL.Common.GUID_DEFAULT);
            clConnection.DoConnection();

            DayCareDataContext db = dbold;

            db.Transaction = tran;
            StaffSchoolYear DBStaffSchoolYear = null;

            try
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.DEBUG, DayCarePL.ModuleToLog.clStaffSchoolYear, "ImportAllActiveStaff", "Debug ImportAllActiveStaff Method", DayCarePL.Common.GUID_DEFAULT);

                /* Guid currentschoolyearid = (from sy in db.SchoolYears
                 *                           where sy.CurrentId.Equals(true) && sy.SchoolId.Equals(SchoolId)
                 *                           select sy.Id).SingleOrDefault(); */
                Guid currentschoolyearid = SchoolYearId;

                List <Guid> lstStaff = (from s in db.Staffs
                                        join ug in db.UserGroups on s.UserGroupId equals ug.Id
                                        join ssy in db.StaffSchoolYears on s.Id equals ssy.StaffId
                                        where ug.SchoolId.Equals(SchoolId) && ssy.active.Equals(true) && ssy.SchoolYearId.Equals(OldCurrentSchoolYearId) &&
                                        !(from sy in db.StaffSchoolYears
                                          where sy.SchoolYearId.Equals(currentschoolyearid)
                                          select sy.StaffId).Contains(s.Id)
                                        select s.Id).ToList();

                foreach (Guid staffid in lstStaff)
                {
                    try
                    {
                        DBStaffSchoolYear              = new StaffSchoolYear();
                        DBStaffSchoolYear.Id           = Guid.NewGuid();
                        DBStaffSchoolYear.StaffId      = staffid;
                        DBStaffSchoolYear.SchoolYearId = SchoolYearId;
                        DBStaffSchoolYear.active       = true;
                        db.StaffSchoolYears.InsertOnSubmit(DBStaffSchoolYear);
                        db.SubmitChanges();
                    }
                    catch
                    { }
                }

                return(true);
            }
            catch (Exception ex)
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.EXCEPTION, DayCarePL.ModuleToLog.clStaffSchoolYear, "ImportAllActiveStaff", ex.Message.ToString(), DayCarePL.Common.GUID_DEFAULT);
                return(false);
            }
        }
예제 #2
0
        public static bool ExportStafftoStaffSchoolYear(Guid StaffId, Guid SchoolId, Guid SchoolYearId, bool Active, System.Data.Common.DbTransaction tran, DayCareDataContext dbold)
        {
            DayCarePL.Logger.Write(DayCarePL.LogType.INFO, DayCarePL.ModuleToLog.clStaffSchoolYear, "ExportStafftoStaffSchoolYear", "Execute ExportStafftoStaffSchoolYear Method", DayCarePL.Common.GUID_DEFAULT);
            clConnection.DoConnection();

            DayCareDataContext db = dbold;

            db.Transaction = tran;
            StaffSchoolYear DBStaffSchoolYear = null;

            try
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.DEBUG, DayCarePL.ModuleToLog.clStaffSchoolYear, "ExportStafftoStaffSchoolYear", "Debug ExportStafftoStaffSchoolYear Method", DayCarePL.Common.GUID_DEFAULT);
                //Guid SchoolYearId = (from sy in db.SchoolYears
                //                     where sy.CurrentId.Equals(true) && sy.SchoolId.Equals(SchoolId)
                //                     select sy.Id).SingleOrDefault();

                int staffcount = (from ssy in db.StaffSchoolYears
                                  where ssy.SchoolYearId.Equals(SchoolYearId) && ssy.StaffId.Equals(StaffId)
                                  select ssy.Id).Count();

                if (staffcount == 0)
                {
                    DBStaffSchoolYear              = new StaffSchoolYear();
                    DBStaffSchoolYear.Id           = Guid.NewGuid();
                    DBStaffSchoolYear.StaffId      = StaffId;
                    DBStaffSchoolYear.SchoolYearId = SchoolYearId;
                    DBStaffSchoolYear.active       = Active;
                    db.StaffSchoolYears.InsertOnSubmit(DBStaffSchoolYear);
                    db.SubmitChanges();
                }
                return(true);
            }
            catch (Exception ex)
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.EXCEPTION, DayCarePL.ModuleToLog.clStaffSchoolYear, "ExportStafftoStaffSchoolYear", ex.Message.ToString(), DayCarePL.Common.GUID_DEFAULT);
                return(false);
            }
        }
예제 #3
0
        public static Guid Save(DayCarePL.StaffProperties objStaff)
        {
            DayCarePL.Logger.Write(DayCarePL.LogType.INFO, DayCarePL.ModuleToLog.clStaff, "Save", "Execute Save Method", DayCarePL.Common.GUID_DEFAULT);
            clConnection.DoConnection();

            DayCareDataContext db = new DayCareDataContext();

            System.Data.Common.DbTransaction tran = null;
            Staff DBStaff = null;
            Guid  StaffId;

            try
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.DEBUG, DayCarePL.ModuleToLog.clStaff, "Save", "Debug Save Method", DayCarePL.Common.GUID_DEFAULT);
                if (db.Connection.State == System.Data.ConnectionState.Closed)
                {
                    db.Connection.Open();
                }
                tran           = db.Connection.BeginTransaction();
                db.Transaction = tran;
                if (objStaff.Id.ToString().Equals(DayCarePL.Common.GUID_DEFAULT))
                {
                    DBStaff                 = new Staff();
                    DBStaff.Id              = System.Guid.NewGuid();
                    DBStaff.CreatedById     = objStaff.CreatedById;
                    DBStaff.CreatedDateTime = DateTime.Now;
                }
                else
                {
                    DBStaff = db.Staffs.SingleOrDefault(u => u.Id.Equals(objStaff.Id));
                }
                DBStaff.LastModifiedById     = objStaff.LastModifiedById;
                DBStaff.LastModifiedDatetime = DateTime.Now;
                DBStaff.UserGroupId          = objStaff.UserGroupId;
                DBStaff.StaffCategoryId      = objStaff.StaffCategoryId;
                DBStaff.FirstName            = objStaff.FirstName;
                DBStaff.LastName             = objStaff.LastName;
                DBStaff.Address1             = objStaff.Address1;
                DBStaff.Address2             = objStaff.Address2;
                DBStaff.City = objStaff.City;
                DBStaff.Zip  = objStaff.Zip;
                if (!objStaff.CountryId.ToString().Equals(DayCarePL.Common.GUID_DEFAULT))
                {
                    DBStaff.CountryId = objStaff.CountryId;
                }
                if (!objStaff.StateId.ToString().Equals(DayCarePL.Common.GUID_DEFAULT))
                {
                    DBStaff.StateId = objStaff.StateId;
                }
                DBStaff.MainPhone        = objStaff.MainPhone;
                DBStaff.SecondaryPhone   = objStaff.SecondaryPhone;
                DBStaff.Email            = objStaff.Email;
                DBStaff.UserName         = objStaff.UserName;
                DBStaff.Password         = objStaff.Password;
                DBStaff.code             = objStaff.Code;
                DBStaff.gender           = objStaff.Gender;
                DBStaff.SecurityQuestion = objStaff.SecurityQuestion;
                DBStaff.SecurityAnswer   = objStaff.SecurityAnswer;
                if (!string.IsNullOrEmpty(objStaff.Photo))
                {
                    DBStaff.Photo = DBStaff.Id + Path.GetExtension(objStaff.Photo);
                }
                else
                {
                    DBStaff.Photo = string.Empty;
                }
                //DBStaff.Active = objStaff.Active;
                DBStaff.Comments = objStaff.Comments;
                DBStaff.Message  = objStaff.Message;
                //DBStaff.IsPrimary = objStaff.IsPrimary;
                if (objStaff.Id.ToString().Equals(DayCarePL.Common.GUID_DEFAULT))
                {
                    db.Staffs.InsertOnSubmit(DBStaff);
                }
                db.SubmitChanges();

                if (!objStaff.Id.ToString().Equals(DayCarePL.Common.GUID_DEFAULT))
                {
                    StaffSchoolYear DBStaffSchoolYear = db.StaffSchoolYears.SingleOrDefault(u => u.StaffId.Equals(objStaff.Id) && u.SchoolYearId.Equals(objStaff.ScoolYearId));
                    DBStaffSchoolYear.StaffId      = objStaff.Id;
                    DBStaffSchoolYear.SchoolYearId = objStaff.ScoolYearId;
                    DBStaffSchoolYear.active       = objStaff.Active;
                    db.SubmitChanges();
                }
                if (objStaff.Active == true)
                {
                    if (DayCareDAL.clStaffSchoolYear.ExportStafftoStaffSchoolYear(DBStaff.Id, objStaff.SchoolId, objStaff.ScoolYearId, objStaff.Active, tran, db))
                    {
                        tran.Commit();
                    }
                    else
                    {
                        tran.Rollback();
                    }
                }
                else
                {
                    tran.Commit();
                }
                StaffId = DBStaff.Id;
            }
            catch (Exception ex)
            {
                DayCarePL.Logger.Write(DayCarePL.LogType.EXCEPTION, DayCarePL.ModuleToLog.clStaff, "Save", ex.Message.ToString(), DayCarePL.Common.GUID_DEFAULT);
                StaffId = new Guid();
                if (tran != null)
                {
                    tran.Rollback();
                }
            }
            finally
            {
                if (db.Connection.State == System.Data.ConnectionState.Open)
                {
                    db.Connection.Close();
                }
            }
            return(StaffId);
        }