Ejemplo n.º 1
0
        private static void UpdatePeople(int pId)
        {
            var    doorsDb = new DOORSEntities();
            var    verpsDb = new VERPSEntities();
            string vUser   = Properties.Settings.Default.vUser;
            string vPass   = Properties.Settings.Default.vPass;
            string vUri    = Properties.Settings.Default.vUri;

            System.Uri myUri = new Uri(vUri);
            VERPSServiceReference.ApplicationData vsr = new VERPSServiceReference.ApplicationData(myUri);
            vsr.Credentials = new NetworkCredential(vUser, vPass, "adm");

            try
            {
                var person = vsr.hrPeople.Where(p => p.Id == pId).SingleOrDefault();
                if (person != null)
                {
                    person.AccessCardID = DateTime.Now.ToString();
                    vsr.UpdateObject(person);
                    Console.WriteLine("OK");
                }
                else
                {
                    Console.WriteLine("YOK!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("CART!");
            }

            vsr.SaveChanges();

            Console.WriteLine("DONE!");
        }
Ejemplo n.º 2
0
        private static void CalcWorkingTimes(DateTime opDate)
        {
            var    doorsDb = new DOORSEntities();
            var    verpsDb = new VERPSEntities();
            string vUser   = Properties.Settings.Default.vUser;
            string vPass   = Properties.Settings.Default.vPass;
            string vUri    = Properties.Settings.Default.vUri;

            System.Uri myUri = new Uri(vUri);
            VERPSServiceReference.ApplicationData vsr = new VERPSServiceReference.ApplicationData(myUri);
            vsr.Credentials = new NetworkCredential(vUser, vPass, "adm");

            int i = 0;
            int j = 0;

            var doorTimes = from d in doorsDb.vwDoorTimes
                            where d.EventDay == opDate
                            select d;

            //////var empTimes = from b in verpsDb.hrWorkingHours
            //////               where b.WorkingDate.Equals(opDate)
            //////               select b;

            foreach (var doorT in doorTimes)
            {
                //////foreach (var empTime in empTimes)
                //////{
                //////    if (doorT.UserExtID == empTime.DoorSysID && doorT.EventDay == empTime.WorkingDate)
                //////    {
                //////        empTime.EntryTime = doorT.EntryTime;
                //////        empTime.ExitTime = doorT.ExitTime;
                //////        empTime.Modified = DateTimeOffset.Now;
                //////    }
                //////}

                string ssss = doorT.UserExtID;
                try
                {
                    //if (ssss == "44B14BDB7D23454CADA5C2FDE8168D80")
                    //{
                    //    string sssssss = "0";
                    //}

                    var doorTime = vsr.hrWorkingHours.Where(p => p.DoorSysID == doorT.UserExtID && p.WorkingDate == doorT.EventDay).SingleOrDefault();
                    if (doorTime != null)
                    {
                        doorTime.EntryTime = doorT.EntryTime;
                        doorTime.ExitTime  = doorT.ExitTime;

                        DateTime startTime = (DateTime)doorT.EntryTime;
                        DateTime endTime   = (DateTime)doorT.ExitTime;
                        TimeSpan timeSpan  = endTime.Subtract(startTime);

                        int workedMinute   = (timeSpan.Hours * 60) + timeSpan.Minutes;
                        int assignedMinute = (int)doorTime.AssignedWorkingHour * 60;
                        int minuteDiff     = workedMinute - assignedMinute;

                        doorTime.TotalHours   = timeSpan.Hours;
                        doorTime.TotalMinutes = timeSpan.Minutes;
                        doorTime.HourDiff     = minuteDiff / 60;
                        doorTime.MinuteDiff   = minuteDiff % 60;

                        if (workedMinute >= 480)
                        {
                            doorTime.TotalHours   = 8;
                            doorTime.TotalMinutes = 0;
                        }


                        vsr.UpdateObject(doorTime);
                        j += 1;
                    }
                }
                catch (Exception ex)
                {
                }

                i += 1;
            }

            vsr.SaveChanges();
            //////verpsDb.SaveChanges();

            Console.WriteLine(i);
            Console.WriteLine(j);
            Console.WriteLine("DONE!");
        }