Example #1
0
        //public CheckInHoursML GetEntityByNoControl(int Id, string ConnectionString)
        //{
        //    try
        //    {
        //        String Query = String.Format("SELECT * FROM {0} WHERE _registry = 1 AND id={1}", TableName, id);
        //        SqlConnection Conexion = new SqlConnection
        //        {
        //            ConnectionString = ConnectionString
        //        };
        //        Conexion.Open();
        //        SqlDataAdapter cmd = new SqlDataAdapter(Query, Conexion);
        //        DataTable dtDepartamentos = new DataTable();
        //        cmd.Fill(dtDepartamentos);
        //        Conexion.Close();
        //        return dtDepartamentos;
        //    }
        //    catch(Exception ex)
        //    {
        //        throw new Exception(String.Format("{0}.GetEntityByNoControl : {1}", core, ex));
        //    }

        //}

        public int Save(CheckInHoursML CheckInHours)
        {
            try
            {
                ModelDAL ModelDAL = new ModelDAL();
                String   Response = ModelDAL.InsertModel(CheckInHours, TableName, IdUserSession);

                SqlConnection Conexion = new SqlConnection()
                {
                    ConnectionString = ConnectionString
                };

                using (SqlCommand cmd2 = new SqlCommand(Response.ToString(), Conexion))
                {
                    Conexion.Open();
                    int newID = (Int32)cmd2.ExecuteScalar();

                    if (Conexion.State == System.Data.ConnectionState.Open)
                    {
                        Conexion.Close();
                    }
                    return(newID);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("{0}.save : {1}", core, ex));
            }
        }
Example #2
0
 public Boolean ExistCheck(CheckInHoursML checkInHours)
 {
     try
     {
         String        Query    = String.Format("select count(*) as count from {0} where _registry=1 and {1}='{2}' and {3}='{4}' and {5}='{6}'", TableName, CheckInHoursML.Database.DateTimeRecord, checkInHours.DateTimeRecord.ToString("yyyy-MM-dd hh:mm:ss"), CheckInHoursML.Database.TypeCheck, checkInHours.TypeCheck, CheckInHoursML.Database.idEmployee, checkInHours.IdEmployee);
         SqlConnection Conexion = new SqlConnection
         {
             ConnectionString = ConnectionString
         };
         using (SqlCommand cmd2 = new SqlCommand(Query.ToString(), Conexion))
         {
             Conexion.Open();
             int newID = (Int32)cmd2.ExecuteScalar();
             Conexion.Close();
             if (newID == 0)
             {
                 return(false);
             }
             else
             {
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.ExistCheck: {1}", core, ex.Message));
     }
 }
Example #3
0
 public void Delete(CheckInHoursML CheckInHours)
 {
     try
     {
         CheckInHoursDAL.Delete(CheckInHours);
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.Delete: {1}", core, ex.Message));
     }
 }
Example #4
0
 public int Save(CheckInHoursML CheckInHours)
 {
     try
     {
         if (CheckInHours.Id == 0)
         {
             return(CheckInHoursDAL.Save(CheckInHours));
         }
         else
         {
             return(CheckInHoursDAL.Update(CheckInHours));
         }
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.Save: {1}", core, ex.Message));
     }
 }
Example #5
0
 public void Delete(CheckInHoursML CheckInHours)
 {
     try
     {
         ModelDAL      ModelDAL = new ModelDAL();
         String        Response = ModelDAL.DeleteModel(CheckInHours, TableName, IdUserSession);
         SqlConnection Conexion = new SqlConnection()
         {
             ConnectionString = ConnectionString
         };
         Conexion.Open();
         SqlCommand cmd2 = new SqlCommand(Response.ToString(), Conexion);
         cmd2.ExecuteNonQuery();
         Conexion.Close();
     }
     catch (Exception ex)
     {
         throw new Exception(String.Format("{0}.delete: {1}", core, ex.Message));
     }
 }
Example #6
0
        //--------------- NUEVA MIGRACION


        public void ListRecord(DateTime Start, DateTime End)
        {
            try
            {
                DataTable       ListRecord      = MigrationHistoryDAL.ListRecord(Start, End);
                TimeOutCheckBLL TimeOutCheckBLL = new TimeOutCheckBLL();
                TurnBLL         TurnBLL         = new TurnBLL();
                DataTable       TimeOutCheckDT  = TimeOutCheckBLL.TimeOutCheck("checkin");
                DataTable       TimeOutCheckMax = TimeOutCheckBLL.TimeOutCheck("maxihours");
                //String TotalAddHours;  //= new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0,0, 0);
                TimeSpan TotalAddHours;
                TimeSpan MaxAddHours;
                int      idGetUser = 0;

                if (TimeOutCheckMax.Rows.Count > 0)
                {
                    MaxAddHours = TimeSpan.Parse(TimeOutCheckMax.Rows[0]["timeCheck"].ToString());
                }
                else
                {
                    MaxAddHours = TimeSpan.Parse("00:00:00");
                }
                //bool SinHoras = false;
                if (TimeOutCheckDT.Rows.Count > 0)
                {
                    //TotalAddHours = TimeOutCheckDT.Rows[0]["timeCheck"].ToString();
                    TotalAddHours = TimeSpan.Parse(TimeOutCheckDT.Rows[0]["timeCheck"].ToString());
                    //SinHoras = true;
                }
                else
                {
                    TotalAddHours = TimeSpan.Parse("00:00:00");
                }
                if (ListRecord.Rows.Count > 0)
                {
                    String         NameTurn     = String.Empty;
                    CheckInHoursML CheckInHours = new CheckInHoursML();
                    foreach (DataRow Record in ListRecord.Rows)
                    {
                        idGetUser = MigrationHistoryDAL.getUserDialing(Record["idUser"].ToString());
                        //Verificar si es MARCACION VALIDA
                        if (MigrationHistoryDAL.ValidRecord(Convert.ToDateTime(Record["dateTimeRecord"].ToString()), TotalAddHours, idGetUser) && idGetUser != 0)
                        {
                            //VERIFICAR SI NO EXISTE UNA MARCACION CON LOS MISMO PARAMETROS
                            if (MigrationHistoryDAL.IsExistRecord(idGetUser, Convert.ToDateTime(Record["dateTimeRecord"].ToString())) == 0)
                            {
                                TurnML TurnUser   = TurnBLL.GetTurnUser(Convert.ToDateTime(Record["dateTimeRecord"].ToString()), idGetUser);
                                String RecordData = MigrationHistoryDAL.RecordOld(idGetUser);
                                if (!String.IsNullOrEmpty(RecordData))
                                {
                                    DateTime RecordOldTime = Convert.ToDateTime(RecordData.ToString());

                                    CheckInHours.IdEmployee     = idGetUser;
                                    CheckInHours.MachineNumber  = 1;
                                    CheckInHours.DateTimeRecord = Convert.ToDateTime(Record["dateTimeRecord"].ToString());
                                    CheckInHours.DateOnlyRecord = Convert.ToDateTime(Record["dateOnlyRecord"].ToString());
                                    CheckInHours.TimeOnlyRecord = TimeSpan.Parse(Record["timeOnlyRecord"].ToString());
                                    CheckInHours.IdTurn         = (TurnUser != null) ? TurnUser.Id : 0;
                                    TimeSpan TotalDiffHours = TotalDiffTime(RecordOldTime, Convert.ToDateTime(Record["dateTimeRecord"].ToString()));
                                    if (MaxAddHours > TotalDiffHours)
                                    {
                                        int Resul = MigrationHistoryDAL.NumRecordsUser(idGetUser) % 2;
                                        CheckInHours.TypeCheck = (Resul == 0)?"ENTRADA":"SALIDA";
                                    }
                                    else
                                    {
                                        CheckInHours.TypeCheck = "ENTRADA";
                                    }
                                }
                                else
                                {
                                    if (TurnUser != null)
                                    {
                                        CheckInHours.IdEmployee     = idGetUser;
                                        CheckInHours.MachineNumber  = 1;
                                        CheckInHours.DateTimeRecord = Convert.ToDateTime(Record["dateTimeRecord"].ToString());
                                        CheckInHours.DateOnlyRecord = Convert.ToDateTime(Record["dateOnlyRecord"].ToString());
                                        CheckInHours.TimeOnlyRecord = TimeSpan.Parse(Record["timeOnlyRecord"].ToString());
                                        CheckInHours.IdTurn         = TurnUser.Id;
                                        CheckInHours.TypeCheck      = "ENTRADA";
                                    }
                                    else
                                    {
                                        CheckInHours.IdEmployee     = idGetUser;
                                        CheckInHours.MachineNumber  = 1;
                                        CheckInHours.DateTimeRecord = Convert.ToDateTime(Record["dateTimeRecord"].ToString());
                                        CheckInHours.DateOnlyRecord = Convert.ToDateTime(Record["dateOnlyRecord"].ToString());
                                        CheckInHours.TimeOnlyRecord = TimeSpan.Parse(Record["timeOnlyRecord"].ToString());
                                        CheckInHours.IdTurn         = 0;
                                        CheckInHours.TypeCheck      = "ENTRADA";
                                    }
                                }
                                CheckInHoursBLL CheckInHoursBLL = new CheckInHoursBLL();
                                CheckInHoursBLL.Save(CheckInHours);
                            }
                        }
                    }
                }
                //return ListRecord;
            }
            catch (Exception ex)
            {
                throw new Exception(String.Format("{0}.ListRecord: {1}", core, ex));
            }
        }