private bool ValidateJobCard(JobCardTime jobCardApp)
 {
     //List<JobCardApp> _Lc = new List<JobCardApp>();
     //DateTime _DTime = new DateTime();
     //DateTime _DTimeLV = new DateTime();
     //_Lc = db.JobCardApps.Where(aa => aa.CriteriaData == jobCardApp.CriteriaData).ToList();
     //foreach (var item in _Lc)
     //{
     //    _DTime = (DateTime)item.DateStarted;
     //    _DTimeLV = (DateTime)jobCardApp.DateStarted;
     //    while (_DTime <= item.DateEnded)
     //    {
     //        while (_DTimeLV <= jobCardApp.DateEnded)
     //        {
     //            if (_DTime == _DTimeLV)
     //                return false;
     //            _DTimeLV = _DTimeLV.AddDays(1);
     //        }
     //        _DTime = _DTime.AddDays(1);
     //    }
     //}
     return true;
 }
 private void RemoveFromAttData(JobCardTime item)
 {
     try
     {
         DateTime date = item.DutyDate.Value;
         List<Emp> emp = db.Emps.Where(aa => aa.EmpID == item.EmpID).ToList();
         ManualProcess mp = new ManualProcess();
         mp.ManualProcessAttendance(date, emp);
     }
     catch (Exception ex)
     {
     }
 }
 private bool AddJCVisitToAttData(JobCardTime jcTime)
 {
     bool check = false;
     try
     {
         //Normal Duty
         using (var context = new TAS2013Entities())
         {
             string empDate = jcTime.EmpID.ToString() + jcTime.DutyDate.Value.ToString("yyMMdd");
             AttData _attdata = context.AttDatas.FirstOrDefault(aa => aa.EmpDate == empDate);
             if (_attdata != null)
             {
                 _attdata.DutyCode = "D";
                 _attdata.StatusAB = false;
                 _attdata.StatusDO = false;
                 _attdata.StatusLeave = false;
                 _attdata.StatusP = true;
                 _attdata.StatusLI = false;
                 _attdata.StatusEO = false;
                 if (_attdata.ShifMin > 0)
                     _attdata.ShifMin = (short)(_attdata.ShifMin - (short)jcTime.TTime.Value.TotalMinutes);
                 else
                     _attdata.ShifMin = (short)jcTime.TTime.Value.TotalMinutes;
                 _attdata.Remarks = "[ODT-Visit]";
                 _attdata.EarlyIn = null;
                 _attdata.EarlyOut = null;
                 _attdata.LateIn = null;
                 _attdata.LateOut = null;
                 _attdata.OTMin = null;
                 _attdata.StatusEI = null;
                 _attdata.StatusEO = null;
                 _attdata.StatusLI = null;
                 _attdata.StatusLO = null;
                 _attdata.StatusP = true;
             }
             context.SaveChanges();
             if (context.SaveChanges() > 0)
                 check = true;
             context.Dispose();
         }
     }
     catch (Exception ex)
     {
     }
     return check;
 }
        private void AddJobCardTimeInAttData(JobCardTime jobCardTime)
        {
            if (db.AttProcesses.Where(aa => aa.ProcessDate == jobCardTime.DutyDate).Count() > 0)
                {
                    switch (jobCardTime.JobCardID)
                    {

                        case 8:// Training
                            AddJCTrainingToAttData(jobCardTime);
                            break;
                        case 9:// Tour
                            AddJCTourToAttData(jobCardTime);
                            break;
                        case 10:// Visit
                            AddJCVisitToAttData(jobCardTime);
                            break;
                        case 11:// Assignment
                            AddJCAssignToAttData(jobCardTime);
                            break;
                    }
                }
        }
 public ActionResult EditAttJobCard()
 {
     User LoggedInUser = Session["LoggedUser"] as User;
     string Message = "";
     QueryBuilder qb = new QueryBuilder();
     string query = qb.MakeCustomizeQuery(LoggedInUser);
     DataTable dt = qb.GetValuesfromDB("select * from EmpView " + query);
     List<EmpView> emps = dt.ToList<EmpView>();
     try
     {
         string _EmpNo = "";
         // int CompID = Convert.ToInt16(Request.Form["CompanyID"].ToString());
         List<EmpView> _Emp = new List<EmpView>();
         short _WorkCardID = Convert.ToInt16(Request.Form["JobCardType"].ToString());
         //First Save Job Card Application
         JobCardTime jobCardTime = new JobCardTime();
         jobCardTime.JobCardID = _WorkCardID;
         jobCardTime.CreatedDate = DateTime.Now;
         jobCardTime.DutyDate = Convert.ToDateTime(Request.Form["JobDate"]);
         string STime = Request.Form["SHour"].ToString();
         string ETime = Request.Form["EHour"].ToString();
         string STimeH = STime.Substring(0, 2);
         string STimeM = STime.Substring(2, 2);
         string ETimeH = ETime.Substring(0, 2);
         string ETimeM = ETime.Substring(2, 2);
         jobCardTime.CreatedBy = LoggedInUser.UserID;
         jobCardTime.AssignedBy = Convert.ToInt16(Request.Form["JobCardDesignation"].ToString());
         jobCardTime.StartTime = new TimeSpan(Convert.ToInt32(STimeH), Convert.ToInt32(STimeM), 0);
         jobCardTime.EndTime = new TimeSpan(Convert.ToInt32(ETimeH), Convert.ToInt32(ETimeM), 0);
         jobCardTime.TTime = (jobCardTime.EndTime - jobCardTime.StartTime);
         //jobCardTime.StartTime = Convert.toti(Request.Form["SHour"]);
         //jobCardTime.EndTime = Convert.ToDateTime(Request.Form["EHour"]);
         string Remakrs = Request.Form["Remakrs"].ToString();
         if (Remakrs != "")
             jobCardTime.Remarks = Remakrs;
         jobCardTime.CreatedBy = LoggedInUser.UserID;
         _EmpNo = Request.Form["JobEmpNo"];
         _Emp = emps.Where(aa => aa.EmpNo == _EmpNo).ToList();
         if (_Emp.Count > 0)
         {
             jobCardTime.EmpID = _Emp.FirstOrDefault().EmpID;
             //if ((jobCardTime.EndTime - jobCardTime.StartTime).TotalMinutes > 0)
             //{
                 if (ValidateJobCard(jobCardTime))
                 {
                     db.JobCardTimes.Add(jobCardTime);
                     if (db.SaveChanges() > 0)
                     {
                         AddJobCardTimeInAttData(jobCardTime);
                         Message = "Job Card Created Sucessfully";
                     }
                     else
                         Message = "Job Card is not created due to server error";
                 }
                 else
                     Message = "Job Card already created for FPID: " + _EmpNo;
             //}
         }
         else
             Message = "No Employee found, Please enter a valid FPID";
         //Add Job Card to JobCardData and Mark Legends in Attendance Data if attendance Created
         Session["EditAttendanceDate"] = DateTime.Today.Date.ToString("yyyy-MM-dd");
         ViewData["datef"] = Session["EditAttendanceDate"].ToString();
         ViewData["JobDate"] = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd");
         ViewBag.JobCardType = new SelectList(db.JobCards, "WorkCardID", "WorkCardName");
         ViewBag.JobCardDesignation = new SelectList(db.Designations, "DesignationID", "DesignationName");
     }
     catch (Exception ex)
     {
         Message = "An Error occured while creating Job Card of " + Request.Form["JobCardType"].ToString();
     }
     //List<EmpView> emps = new List<EmpView>();
     ViewData["JobDate"] = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd");
     ViewBag.JobCardType = new SelectList(db.JobCards, "WorkCardID", "WorkCardName");
     ViewBag.JobCardDesignation = new SelectList(db.Designations, "DesignationID", "DesignationName");
     ViewBag.CMessage = Message;
     ViewBag.CurrentFilter = "";
     int pageSize = 10;
     int? page = 1;
     int pageNumber = (page ?? 1);
     return View("Index", emps.ToPagedList(pageNumber, pageSize));
 }