public Core.Business.StimulationApplicationForCrew FindMachineGroupNewestAppforCrew(Guid Id, string MachineID)
        {
            SqlServerUtility sql = new SqlServerUtility();
            string sqlstr = "SELECT [dbo].[StimulationApplicationForCrew].* FROM [StimulationApplicationForCrew] JOIN [dbo].[StimulationAppliction] ON [dbo].[StimulationApplicationForCrew].Id=[dbo].[StimulationAppliction].Id and [dbo].[StimulationAppliction].StimulationAndTypeId='";
            sqlstr += Id + "' Where CrewId='";
            sqlstr += MachineID + "'";
            SqlDataReader reader = sql.ExecuteSqlReader(sqlstr);

            if (reader != null && !reader.IsClosed && reader.Read())
            {
                Core.Business.StimulationApplicationForCrew stimulationApplicationForCrew = new Core.Business.StimulationApplicationForCrew();

                if (!reader.IsDBNull(0)) stimulationApplicationForCrew.Id = reader.GetGuid(0);
                if (!reader.IsDBNull(1)) stimulationApplicationForCrew.CrewId = reader.GetGuid(1);
                if (!reader.IsDBNull(2)) stimulationApplicationForCrew.FieldType = reader.GetGuid(2);
                if (!reader.IsDBNull(3)) stimulationApplicationForCrew.StimulationContentType = reader.GetInt32(3);
                if (!reader.IsDBNull(4)) stimulationApplicationForCrew.DraftWriter = reader.GetString(4);
                if (!reader.IsDBNull(5)) stimulationApplicationForCrew.DetailWriter = reader.GetString(5);
                if (!reader.IsDBNull(6)) stimulationApplicationForCrew.FillDate = reader.GetDateTime(6);
                if (!reader.IsDBNull(7)) stimulationApplicationForCrew.State = reader.GetInt32(7);
                if (!reader.IsDBNull(8)) stimulationApplicationForCrew.Hours = reader.GetInt32(8);
                if (!reader.IsDBNull(9)) stimulationApplicationForCrew.ProjectNbr = reader.GetString(9);
                if (!reader.IsDBNull(10)) stimulationApplicationForCrew.ComplaitTime = reader.GetInt32(10);
                if (!reader.IsDBNull(11)) stimulationApplicationForCrew.Notice = reader.GetString(11);
                if (!reader.IsDBNull(12)) stimulationApplicationForCrew.Record = reader.GetString(12);
                if (!reader.IsDBNull(13)) stimulationApplicationForCrew.ServiceObjectCase = reader.GetString(13);
                if (!reader.IsDBNull(14)) stimulationApplicationForCrew.DynamicInfoCollectingBox = reader.GetString(14);
                if (!reader.IsDBNull(15)) stimulationApplicationForCrew.ExemplaryDeed = reader.GetString(15);
                if (!reader.IsDBNull(16)) stimulationApplicationForCrew.PaperNbr = reader.GetString(16);
                if (!reader.IsDBNull(17)) stimulationApplicationForCrew.FunctionDevelopNbr = reader.GetString(17);
                if (!reader.IsDBNull(18)) stimulationApplicationForCrew.Score = reader.GetInt32(18);

                reader.Close();
                stimulationApplicationForCrew.MarkOld();
                return stimulationApplicationForCrew;
            }
            else
            {
                if (reader != null && !reader.IsClosed)
                    reader.Close();

                return null;
            }
        }
        public IList<Core.Business.StimulationApplicationForCrew> GetAllStimulationApplicationForCrew()
        {
            IList<Core.Business.StimulationApplicationForCrew> stimulationApplicationForCrewlist = new List<Core.Business.StimulationApplicationForCrew>();
            SqlServerUtility sql = new SqlServerUtility();

            SqlDataReader reader = sql.ExecuteSPReader("usp_SelectStimulationApplicationForCrewsAll");

            if (reader != null)
            {
                while (reader.Read())
                {
                    Core.Business.StimulationApplicationForCrew stimulationApplicationForCrew = new Core.Business.StimulationApplicationForCrew();

                    if (!reader.IsDBNull(0)) stimulationApplicationForCrew.Id = reader.GetGuid(0);
                    if (!reader.IsDBNull(1)) stimulationApplicationForCrew.CrewId = reader.GetGuid(1);
                    if (!reader.IsDBNull(2)) stimulationApplicationForCrew.FieldType = reader.GetGuid(2);
                    if (!reader.IsDBNull(3)) stimulationApplicationForCrew.StimulationContentType = reader.GetInt32(3);
                    if (!reader.IsDBNull(4)) stimulationApplicationForCrew.DraftWriter = reader.GetString(4);
                    if (!reader.IsDBNull(5)) stimulationApplicationForCrew.DetailWriter = reader.GetString(5);
                    if (!reader.IsDBNull(6)) stimulationApplicationForCrew.FillDate = reader.GetDateTime(6);
                    if (!reader.IsDBNull(7)) stimulationApplicationForCrew.State = reader.GetInt32(7);
                    if (!reader.IsDBNull(8)) stimulationApplicationForCrew.Hours = reader.GetInt32(8);
                    if (!reader.IsDBNull(9)) stimulationApplicationForCrew.ProjectNbr = reader.GetString(9);
                    if (!reader.IsDBNull(10)) stimulationApplicationForCrew.ComplaitTime = reader.GetInt32(10);
                    if (!reader.IsDBNull(11)) stimulationApplicationForCrew.Notice = reader.GetString(11);
                    if (!reader.IsDBNull(12)) stimulationApplicationForCrew.Record = reader.GetString(12);
                    if (!reader.IsDBNull(13)) stimulationApplicationForCrew.ServiceObjectCase = reader.GetString(13);
                    if (!reader.IsDBNull(14)) stimulationApplicationForCrew.DynamicInfoCollectingBox = reader.GetString(14);
                    if (!reader.IsDBNull(15)) stimulationApplicationForCrew.ExemplaryDeed = reader.GetString(15);
                    if (!reader.IsDBNull(16)) stimulationApplicationForCrew.PaperNbr = reader.GetString(16);
                    if (!reader.IsDBNull(17)) stimulationApplicationForCrew.FunctionDevelopNbr = reader.GetString(17);
                    if (!reader.IsDBNull(18)) stimulationApplicationForCrew.Score = reader.GetInt32(18);

                    stimulationApplicationForCrew.MarkOld();
                    stimulationApplicationForCrewlist.Add(stimulationApplicationForCrew);
                }
                reader.Close();
            }
            return stimulationApplicationForCrewlist;
        }
        public Core.Business.StimulationApplicationForCrew Select(Guid id)
        {
            SqlServerUtility sql = new SqlServerUtility();

            sql.AddParameter("@Id", SqlDbType.UniqueIdentifier, id);
            SqlDataReader reader = sql.ExecuteSPReader("usp_SelectStimulationApplicationForCrew");

            if (reader != null && !reader.IsClosed && reader.Read())
            {
                Core.Business.StimulationApplicationForCrew stimulationApplicationForCrew = new Core.Business.StimulationApplicationForCrew();

                if (!reader.IsDBNull(0)) stimulationApplicationForCrew.Id = reader.GetGuid(0);
                if (!reader.IsDBNull(1)) stimulationApplicationForCrew.CrewId = reader.GetGuid(1);
                if (!reader.IsDBNull(2)) stimulationApplicationForCrew.FieldType = reader.GetGuid(2);
                if (!reader.IsDBNull(3)) stimulationApplicationForCrew.StimulationContentType = reader.GetInt32(3);
                if (!reader.IsDBNull(4)) stimulationApplicationForCrew.DraftWriter = reader.GetString(4);
                if (!reader.IsDBNull(5)) stimulationApplicationForCrew.DetailWriter = reader.GetString(5);
                if (!reader.IsDBNull(6)) stimulationApplicationForCrew.FillDate = reader.GetDateTime(6);
                if (!reader.IsDBNull(7)) stimulationApplicationForCrew.State = reader.GetInt32(7);
                if (!reader.IsDBNull(8)) stimulationApplicationForCrew.Hours = reader.GetInt32(8);
                if (!reader.IsDBNull(9)) stimulationApplicationForCrew.ProjectNbr = reader.GetString(9);
                if (!reader.IsDBNull(10)) stimulationApplicationForCrew.ComplaitTime = reader.GetInt32(10);
                if (!reader.IsDBNull(11)) stimulationApplicationForCrew.Notice = reader.GetString(11);
                if (!reader.IsDBNull(12)) stimulationApplicationForCrew.Record = reader.GetString(12);
                if (!reader.IsDBNull(13)) stimulationApplicationForCrew.ServiceObjectCase = reader.GetString(13);
                if (!reader.IsDBNull(14)) stimulationApplicationForCrew.DynamicInfoCollectingBox = reader.GetString(14);
                if (!reader.IsDBNull(15)) stimulationApplicationForCrew.ExemplaryDeed = reader.GetString(15);
                if (!reader.IsDBNull(16)) stimulationApplicationForCrew.PaperNbr = reader.GetString(16);
                if (!reader.IsDBNull(17)) stimulationApplicationForCrew.FunctionDevelopNbr = reader.GetString(17);
                if (!reader.IsDBNull(18)) stimulationApplicationForCrew.Score = reader.GetInt32(18);

                reader.Close();
                return stimulationApplicationForCrew;
            }
            else
            {
                if (reader != null && !reader.IsClosed)
                    reader.Close();

                return null;
            }
        }
        public IList<Core.Business.StimulationApplicationForCrew> GetStimulationApplicationByUnitId(Guid unitId, Guid typeId)
        {
            IList<Core.Business.StimulationApplicationForCrew> stimulationlist = new List<Core.Business.StimulationApplicationForCrew>();
            SqlServerUtility sql = new SqlServerUtility();
            string sqlstr = "Select  b.* from  MACHINESET a,StimulationApplicationForCrew b ,StimulationAppliction c where a.id= b.CrewId and b.state=12  and b.Id=c.Id and a.UnitID='" + unitId + "' and c.StimulationAndTypeId='" + typeId + "' order by Id desc";
            SqlDataReader reader = sql.ExecuteSqlReader(sqlstr);
            if (reader != null)
            {
                while (reader.Read())
                {
                    Core.Business.StimulationApplicationForCrew stimulationApplicationForCrew = new Core.Business.StimulationApplicationForCrew();

                    if (!reader.IsDBNull(0)) stimulationApplicationForCrew.Id = reader.GetGuid(0);
                    if (!reader.IsDBNull(1)) stimulationApplicationForCrew.CrewId = reader.GetGuid(1);
                    if (!reader.IsDBNull(2)) stimulationApplicationForCrew.FieldType = reader.GetGuid(2);
                    if (!reader.IsDBNull(3)) stimulationApplicationForCrew.StimulationContentType = reader.GetInt32(3);
                    if (!reader.IsDBNull(4)) stimulationApplicationForCrew.DraftWriter = reader.GetString(4);
                    if (!reader.IsDBNull(5)) stimulationApplicationForCrew.DetailWriter = reader.GetString(5);
                    if (!reader.IsDBNull(6)) stimulationApplicationForCrew.FillDate = reader.GetDateTime(6);
                    if (!reader.IsDBNull(7)) stimulationApplicationForCrew.State = reader.GetInt32(7);
                    if (!reader.IsDBNull(8)) stimulationApplicationForCrew.Hours = reader.GetInt32(8);
                    if (!reader.IsDBNull(9)) stimulationApplicationForCrew.ProjectNbr = reader.GetString(9);
                    if (!reader.IsDBNull(10)) stimulationApplicationForCrew.ComplaitTime = reader.GetInt32(10);
                    if (!reader.IsDBNull(11)) stimulationApplicationForCrew.Notice = reader.GetString(11);
                    if (!reader.IsDBNull(12)) stimulationApplicationForCrew.Record = reader.GetString(12);
                    if (!reader.IsDBNull(13)) stimulationApplicationForCrew.ServiceObjectCase = reader.GetString(13);
                    if (!reader.IsDBNull(14)) stimulationApplicationForCrew.DynamicInfoCollectingBox = reader.GetString(14);
                    if (!reader.IsDBNull(15)) stimulationApplicationForCrew.ExemplaryDeed = reader.GetString(15);
                    if (!reader.IsDBNull(16)) stimulationApplicationForCrew.PaperNbr = reader.GetString(16);
                    if (!reader.IsDBNull(17)) stimulationApplicationForCrew.FunctionDevelopNbr = reader.GetString(17);
                    if (!reader.IsDBNull(18)) stimulationApplicationForCrew.Score = reader.GetInt32(18);

                    stimulationApplicationForCrew.MarkOld();
                    stimulationlist.Add(stimulationApplicationForCrew);
                }
                reader.Close();
            }
            return stimulationlist;
        }