Пример #1
0
        public static LeaveDaysDetails GetLeaveDaysDetails(clsLeavePost tPost)
        {
            string Location = tPost.Location;

            LeaveDaysDetails t1    = new LeaveDaysDetails();
            string           cnstr = string.Empty;

            try
            {
                cnstr = ConfigurationManager.ConnectionStrings["cn" + Location].ConnectionString;
            }
            catch (Exception ex)
            {
                return(t1);
            }


            DateTime FromDt = tPost.FromDate, ToDt = tPost.ToDate;
            decimal  TotDays = 0, WODayNo = 0, HLDay = 0;
            bool     halfflg = false;

            halfflg = tPost.HalfDay;

            TimeSpan ts = (tPost.ToDate - tPost.FromDate);

            TotDays = ts.Days + 1;

            string err   = string.Empty;
            string WOSql = "Select Count(*) From AttdData where CompCode = '01' and WrkGrp = 'Comp' and ScheduleShift ='WO' and  tDate between '" + tPost.FromDate.ToString("yyyy-MM-dd") + "' And '" + ToDt.ToString("yyyy-MM-dd") + "'" +
                           " And EmpUnqID='" + tPost.EmpUnqID + "'";

            WODayNo = Convert.ToDecimal(Utils.GetDescription(WOSql, cnstr, out err));


            string hlsql = "Select tDate from HoliDayMast Where " +
                           " CompCode = '01' " +
                           " And WrkGrp ='COMP'" +
                           " And tDate between '" + tPost.FromDate.ToString("yyyy-MM-dd") + "' and '" + ToDt.ToString("yyyy-MM-dd") + "' ";

            //'check hlDay on WeekOff...

            HLDay = 0;
            DataSet ds      = Utils.GetData(hlsql, cnstr, out err);
            bool    hasRows = ds.Tables.Cast <DataTable>().Any(table => table.Rows.Count != 0);

            if (hasRows)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    //Get  from AttdData Table , if ScheduleShift = "WO" on Holiday
                    WOSql = "Select ScheduleShift from AttdData Where EmpUnqId ='" + tPost.EmpUnqID + "' and tDate ='" + Convert.ToDateTime(dr["tDate"]).ToString("yyyy-MM-dd") + "'";
                    string WODay = Utils.GetDescription(WOSql, cnstr, out err);
                    if (WODay == "WO")
                    {
                        WODayNo -= 1;
                    }
                    HLDay += 1;
                }
            }

            t1.TotDays = TotDays;
            if (tPost.LeaveTyp.Trim() == "AB" || tPost.LeaveTyp.Trim() == "LW" || tPost.LeaveTyp.Trim() == "SP" || tPost.LeaveTyp.Trim() == "OH")
            {
                WODayNo = 0;
                HLDay   = 0;
            }

            t1.WoDays = WODayNo;
            t1.HLDays = HLDay;

            if (halfflg)
            {
                t1.IsHalf    = true;
                t1.LeaveDays = (TotDays - (WODayNo + HLDay)) / 2;
            }
            else
            {
                t1.IsHalf    = false;
                t1.LeaveDays = (TotDays - (WODayNo + HLDay));
            }

            return(t1);
        }
Пример #2
0
        public static string LeaveDataValidate(clsLeavePost t)
        {
            string Location = t.Location;

            string err = string.Empty;

            string cnstr = string.Empty;

            try
            {
                cnstr = ConfigurationManager.ConnectionStrings["cn" + Location].ConnectionString;
            }
            catch (Exception ex)
            {
                err = ex.Message;
                return(err);
            }


            if (string.IsNullOrEmpty(t.EmpUnqID.ToString()))
            {
                err = err + "EmpUnqID required" + Environment.NewLine;
                return(err);
            }

            string sql    = "Select Active from MastEmp where CompCode = '01' and WrkGrp = 'Comp' and EmpUnqID ='" + t.EmpUnqID + "'";
            string result = GetDescription(sql, cnstr, out err);

            if (!string.IsNullOrEmpty(err))
            {
                return(err);
            }

            if (string.IsNullOrEmpty(result))
            {
                err += "Invalid Employee : in Data Validate";
                return(err);
            }

            if (t.FromDate == DateTime.MinValue)
            {
                err += "Invalid From Date : in Data Validate";
                return(err);
            }

            if (t.ToDate == DateTime.MinValue)
            {
                err += "Invalid To Date : in Data Validate ";
                return(err);
            }

            if (t.FromDate > t.ToDate)
            {
                err += "Invalid Date Range : in Data Validate";
                return(err);
            }

            if (t.ToDate.Year != t.FromDate.Year)
            {
                err += "Invalid Date Range : Cross Year Date Posting not allowed";
                return(err);
            }


            #region Chk_AlreadyPosted
            sql = "Select * from LeaveEntry Where " +
                  " compcode = '01'" +
                  " and WrkGrp ='COMP'" +
                  " And tYear ='" + t.FromDate.Year + "'" +
                  " And EmpUnqID='" + t.EmpUnqID + "'" +
                  " And (     FromDt between '" + t.FromDate.ToString("yyyy-MM-dd") + "' And '" + t.ToDate.ToString("yyyy-MM-dd") + "' " +
                  "  OR       ToDt Between '" + t.FromDate.ToString("yyyy-MM-dd") + "'   And '" + t.ToDate.ToString("yyyy-MM-dd") + "' " +
                  "  OR '" + t.FromDate.ToString("yyyy-MM-dd") + "' Between FromDt And ToDt " +
                  "  OR '" + t.ToDate.ToString("yyyy-MM-dd") + "' Between FromDt And ToDt " +
                  "     ) ";

            string  err2;
            DataSet ds      = Utils.GetData(sql, cnstr, out err2);
            bool    hasRows = ds.Tables.Cast <DataTable>().Any(table => table.Rows.Count != 0);
            err += err2;
            if (hasRows)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                err += "Some Leave Already Posted : in Data Validate";
                return(err);
            }
            #endregion


            #region Chk_ValidLeaveTyp

            sql = "Select * from MastLeave where " +
                  " compcode = '01'" +
                  " and WrkGrp ='comp'" +
                  " and LeaveTyp ='" + t.LeaveTyp + "'";

            ds      = Utils.GetData(sql, cnstr, out err2);
            err    += err2;
            hasRows = ds.Tables.Cast <DataTable>().Any(table => table.Rows.Count != 0);

            if (!hasRows)
            {
                err += "Invalid Leave Type : in Data Validate";
                return(err);
            }


            List <clsLeaveBal> tlstbal = Utils.GetLeaveBal(Convert.ToInt32(t.EmpUnqID), t.FromDate.Year, t.LeaveTyp, Location);
            foreach (clsLeaveBal tbal in tlstbal)
            {
                if (tbal.IsBalanced && tbal.Balance <= 0)
                {
                    err += "Balance not found : in Data Validate";
                    return(err);
                }
            }



            #endregion


            return(err);
        }