Ejemplo n.º 1
0
        public static void UpdateAttendanceData(IUnitOfWork _unitOfWork, AttendanceBase objAtt, EnrolledEmployee employee,
                                                string strTableName, bool isClientCall)
        {
            try
            {
                if (isClientCall == false)
                {
                    if (employee.type == enEmpType.Casual)
                    {
                        AttCasual objC = (AttCasual)objAtt;
                        if (objAtt.isNewRecord)
                        {
                            _unitOfWork.AttCasuals.Insert(objC);
                        }
                        else
                        {
                            _unitOfWork.AttCasuals.Update(objC);
                        }
                    }
                    else if (employee.type == enEmpType.Permanent)
                    {
                        AttPermanent objC = (AttPermanent)objAtt;
                        if (objAtt.isNewRecord)
                        {
                            _unitOfWork.AttPermanents.Insert(objC);
                        }
                        else
                        {
                            _unitOfWork.AttPermanents.Update(objC);
                        }
                    }
                    else if (employee.type == enEmpType.Contract)
                    {
                        AttContract objC = (AttContract)objAtt;
                        if (objAtt.isNewRecord)
                        {
                            _unitOfWork.AttContracts.Insert(objC);
                        }
                        else
                        {
                            _unitOfWork.AttContracts.Update(objC);
                        }
                    }
                    _unitOfWork.Commit();
                }
                else
                {
                    using (var db = new iTimeServiceContext())
                    {
                        var debug = new SqlParameter("@debug", false);

                        var Table_Name = strTableName != null ?
                                         new SqlParameter("@Table_Name", strTableName) :
                                         new SqlParameter("@Table_Name", SqlDbType.VarChar);

                        var empid = objAtt.empid != null ?
                                    new SqlParameter("@empid", objAtt.empid) :
                                    new SqlParameter("@empid", SqlDbType.Int);

                        var id = objAtt.id != null ?
                                 new SqlParameter("@id", objAtt.id) :
                                 new SqlParameter("@id", SqlDbType.Int);

                        var shiftid = objAtt.shiftid != null ?
                                      new SqlParameter("@shiftid", objAtt.shiftid) :
                                      new SqlParameter("@shiftid", SqlDbType.Int);

                        var daytype = objAtt.daytype != null ?
                                      new SqlParameter("@daytype", objAtt.daytype) :
                                      new SqlParameter("@daytype", SqlDbType.Int);

                        var shifttype = objAtt.shifttype != null ?
                                        new SqlParameter("@shifttype", objAtt.shifttype) :
                                        new SqlParameter("@shifttype", SqlDbType.VarChar);

                        var isabsent = objAtt.isabsent != null ?
                                       new SqlParameter("@isabsent", objAtt.isabsent) :
                                       new SqlParameter("@isabsent", SqlDbType.Bit);

                        var attstatus = objAtt.attstatus != null ?
                                        new SqlParameter("@attstatus", objAtt.attstatus) :
                                        new SqlParameter("@attstatus", SqlDbType.Int);

                        var timein = objAtt.timein != null ?
                                     new SqlParameter("@timein", objAtt.timein) :
                                     new SqlParameter("@timein", DBNull.Value);

                        var timeout = objAtt.timeout != null ?
                                      new SqlParameter("@timeout", objAtt.timeout) :
                                      new SqlParameter("@timeout", DBNull.Value);

                        var timeinE = objAtt.timeinE != null ?
                                      new SqlParameter("@timeinE", objAtt.timeinE) :
                                      new SqlParameter("@timeinE", DBNull.Value);

                        var timeoutE = objAtt.timeoutE != null ?
                                       new SqlParameter("@timeoutE", objAtt.timeoutE) :
                                       new SqlParameter("@timeoutE", DBNull.Value);

                        var breakout = objAtt.breakout != null ?
                                       new SqlParameter("@breakout", objAtt.breakout) :
                                       new SqlParameter("@breakout", DBNull.Value);

                        var breakin = objAtt.breakin != null ?
                                      new SqlParameter("@breakin", objAtt.breakin) :
                                      new SqlParameter("@breakin", DBNull.Value);

                        var totalhrscount = objAtt.totalhrscount != null ?
                                            new SqlParameter("@totalhrscount", objAtt.totalhrscount) :
                                            new SqlParameter("@totalhrscount", SqlDbType.Float);

                        var totalhrsworked = objAtt.totalhrsworked != null ?
                                             new SqlParameter("@totalhrsworked", objAtt.totalhrsworked) :
                                             new SqlParameter("@totalhrsworked", SqlDbType.Float);

                        var normalhrsworked = objAtt.normalhrsworked != null ?
                                              new SqlParameter("@normalhrsworked", objAtt.normalhrsworked) :
                                              new SqlParameter("@normalhrsworked", SqlDbType.Float);

                        var otHD = objAtt.otHD != null ?
                                   new SqlParameter("@otHD", objAtt.otHD) :
                                   new SqlParameter("@otHD", SqlDbType.Float);

                        var otND = objAtt.otND != null ?
                                   new SqlParameter("@otND", objAtt.otND) :
                                   new SqlParameter("@otND", SqlDbType.Float);

                        var breaktm = objAtt.breaktm != null ?
                                      new SqlParameter("@breaktm", objAtt.breaktm) :
                                      new SqlParameter("@breaktm", SqlDbType.Float);

                        var leaveouts = objAtt.leaveouts != null ?
                                        new SqlParameter("@leaveouts", objAtt.leaveouts) :
                                        new SqlParameter("@leaveouts", SqlDbType.Float);

                        var losthrs = objAtt.losthrs != null ?
                                      new SqlParameter("@losthrs", objAtt.losthrs) :
                                      new SqlParameter("@losthrs", SqlDbType.Float);

                        var adjot = objAtt.adjot != null ?
                                    new SqlParameter("@adjot", objAtt.adjot) :
                                    new SqlParameter("@adjot", SqlDbType.Float);

                        var timeinM = objAtt.timeinM != null ?
                                      new SqlParameter("@timeinM", objAtt.timeinM) :
                                      new SqlParameter("@timeinM", SqlDbType.Bit);

                        var timeoutM = objAtt.timeoutM != null ?
                                       new SqlParameter("@timeoutM", objAtt.timeoutM) :
                                       new SqlParameter("@timeoutM", SqlDbType.Bit);

                        var weekday = objAtt.weekday != null ?
                                      new SqlParameter("@weekday", objAtt.weekday) :
                                      new SqlParameter("@weekday", SqlDbType.Int);

                        var comment = objAtt.comment != null ?
                                      new SqlParameter("@comment", objAtt.comment) :
                                      new SqlParameter("@comment", SqlDbType.VarChar);

                        var earlygo = objAtt.earlygo != null ?
                                      new SqlParameter("@earlygo", objAtt.earlygo) :
                                      new SqlParameter("@earlygo", SqlDbType.Float);

                        var latein = objAtt.latein != null ?
                                     new SqlParameter("@latein", objAtt.latein) :
                                     new SqlParameter("@latein", SqlDbType.Float);

                        var timeinP = objAtt.timeinP != null ?
                                      new SqlParameter("@timeinP", objAtt.timeinP) :
                                      new SqlParameter("@timeinP", SqlDbType.Float);

                        var timeoutP = objAtt.timeoutP != null ?
                                       new SqlParameter("@timeoutP", objAtt.timeoutP) :
                                       new SqlParameter("@timeoutP", SqlDbType.Float);

                        var lunchP = objAtt.lunchP != null ?
                                     new SqlParameter("@lunchP", objAtt.lunchP) :
                                     new SqlParameter("@lunchP", SqlDbType.Float);

                        var chlocked = objAtt.chlocked != null ?
                                       new SqlParameter("@chlocked", objAtt.chlocked) :
                                       new SqlParameter("@chlocked", SqlDbType.Bit);

                        var finallost = objAtt.finallost != null ?
                                        new SqlParameter("@finallost", objAtt.finallost) :
                                        new SqlParameter("@finallost", SqlDbType.Float);

                        var adjlost = objAtt.adjlost != null ?
                                      new SqlParameter("@adjlost", objAtt.adjlost) :
                                      new SqlParameter("@adjlost", SqlDbType.Float);

                        var finalot = objAtt.finalot != null ?
                                      new SqlParameter("@finalot", objAtt.finalot) :
                                      new SqlParameter("@finalot", SqlDbType.Float);

                        var lunchlost = objAtt.lunchlost != null ?
                                        new SqlParameter("@lunchlost", objAtt.lunchlost) :
                                        new SqlParameter("@lunchlost", SqlDbType.Float);

                        db.Database.ExecuteSqlCommand("spDynamicAttendanceUpdate @debug,@Table_Name,@empid,@id," +
                                                      "@shiftid,@daytype,@shifttype,@isabsent,@attstatus,@timein,@timeout,@timeinE,@timeoutE," +
                                                      "@breakout,@breakin,@totalhrscount,@totalhrsworked,@normalhrsworked,@otHD,@otND,@breaktm," +
                                                      "@leaveouts,@losthrs,@adjot,@timeinM,@timeoutM,@weekday,@comment,@earlygo,@latein,@timeinP," +
                                                      "@timeoutP,@lunchP,@chlocked,@finallost,@adjlost,@finalot,@lunchlost",
                                                      debug, Table_Name, empid, id, shiftid, daytype, shifttype, isabsent, attstatus, timein, timeout, timeinE, timeoutE,
                                                      breakout, breakin, totalhrscount, totalhrsworked, normalhrsworked, otHD, otND, breaktm, leaveouts, losthrs, adjot,
                                                      timeinM, timeoutM, weekday, comment, earlygo, latein, timeinP, timeoutP, lunchP, chlocked, finallost, adjlost, finalot, lunchlost);

                        _processedOk = true;
                    }
                }
            }
            catch (Exception ex)
            {
                _processedOk = false;
                _exception   = ex;
            }
        }
Ejemplo n.º 2
0
        public static AttendanceBase InitializeAttendanceObject(IUnitOfWork unitOfWork, EnrolledEmployee emp, DateTime dateToProcess, string tableName)
        {
            try
            {
                AttendanceBase objAtt = new AttendanceBase();
                if (tableName == "")
                {
                    if (emp.type == enEmpType.Casual)
                    {
                        objAtt = unitOfWork.AttCasuals.All()
                                 .Where(x => x.empid == emp.id)
                                 .Where(x => DbFunctions.TruncateTime(x.attenddt) == dateToProcess.Date)
                                 .FirstOrDefault();
                        if (objAtt == null) // insert new rec
                        {
                            objAtt = new AttCasual
                            {
                                empid       = emp.id,
                                attenddt    = dateToProcess.Date,
                                weekday     = (int)dateToProcess.DayOfWeek,
                                attstatus   = (int)enAttStatus.Work,
                                isNewRecord = true,
                                compid      = emp.compid,
                                userid      = 999
                            };
                        }
                        objAtt = (AttCasual)objAtt;
                    }
                    else if (emp.type == enEmpType.Permanent)
                    {
                        objAtt = unitOfWork.AttPermanents.All()
                                 .Where(x => x.empid == emp.id)
                                 .Where(x => DbFunctions.TruncateTime(x.attenddt) == dateToProcess.Date)
                                 .FirstOrDefault();

                        //if no record for this casual emp then initialize record and continue
                        if (objAtt == null) // insert new rec
                        {
                            objAtt = new AttPermanent
                            {
                                empid       = emp.id,
                                attenddt    = dateToProcess.Date,
                                weekday     = (int)dateToProcess.DayOfWeek,
                                attstatus   = (int)enAttStatus.Work,
                                isNewRecord = true,
                                compid      = emp.compid,
                                userid      = 999
                            };
                        }
                        objAtt = (AttPermanent)objAtt;
                    }
                    else if (emp.type == enEmpType.Contract)
                    {
                        objAtt = unitOfWork.AttContracts.All()
                                 .Where(x => x.empid == emp.id)
                                 .Where(x => DbFunctions.TruncateTime(x.attenddt) == dateToProcess.Date)
                                 .FirstOrDefault();


                        if (objAtt == null) // insert new rec
                        {
                            objAtt = new AttContract
                            {
                                empid       = emp.id,
                                attenddt    = dateToProcess.Date,
                                weekday     = (int)dateToProcess.DayOfWeek,
                                attstatus   = (int)enAttStatus.Work,
                                isNewRecord = true,
                                compid      = emp.compid,
                                userid      = 999
                            };
                        }
                        objAtt = (AttContract)objAtt;
                    }
                }
                else
                {
                    using (var db = new iTimeServiceContext())
                    {
                        object[] parameters = { tableName, emp.id, dateToProcess.Date };
                        string   strFillObj = "SELECT * FROM " + tableName + "  WHERE empid =" + emp.id + " AND " +
                                              " CONVERT(VARCHAR(10), attenddt,120) ='" + dateToProcess.Date.ToString("yyyy-MM-dd") + "'";

                        var obj = db.Database.SqlQuery <AttendanceBase>(strFillObj).FirstOrDefault();
                        objAtt = (AttendanceBase)obj;
                    }
                }
                return(objAtt);
            }
            catch (Exception ex)
            {
                _processedOk = false;
                _exception   = ex;
                return(null);
            }
        }