コード例 #1
0
 public ActionResult Save(JobCardCompletion model)
 {
     try
     {
         JobOrderCompletionRepository repo = new JobOrderCompletionRepository();
         repo.UpdateJobCardCompletion(model, UserID.ToString());
         if (model.isOnHold)
         {
             TempData["success"] = model.JobCardNo + " has been put on hold";
         }
         else
         {
             TempData["success"] = "Saved Successfully (" + model.JobCardNo + ")";
         }
         return(RedirectToAction("Index", new { isProjectBased = model.isProjectBased }));
     }
     catch (Exception)
     {
         TempData["error"] = "Some error occured. Please try again.";
         return(View("Create", model));
     }
 }
コード例 #2
0
        public int UpdateJobCardCompletion(JobCardCompletion jobcard, string CreatedBy)
        {
            int id = 0;

            using (IDbConnection connection = OpenConnection(dataConnection))
            {
                IDbTransaction txn = connection.BeginTransaction();
                try
                {
                    string query = "update JobCard set JodCardCompleteStatus = 1, JodCardCompletedDate='" +
                                   jobcard.JobCardCompletedDate.ToString("dd-MMM-yyyy") +
                                   "', WarrentyPeriod = '" + jobcard.WarrentyPeriod.ToString("dd/MMM/yyyy") + "'" +
                                   (jobcard.isOnHold ? ", isOnHold = 1, HeldBy = " + CreatedBy + ", HeldOn = GETDATE()" : "") +
                                   " where jobCardId=" + jobcard.JobCardId.ToString();
                    var count = connection.Query(query, transaction: txn);
                    if (jobcard.isOnHold)
                    {
                        goto commit;
                    }
                    //query = @"UPDATE JobCardQC JQ SET JQ.IsQCPassed =1 inner join JobCard J on J.JobCardId=JQ.JobCardId   WHERE J.isService=1 AND JQ.JobCardId = " + jobcard.JobCardId + "";
                    //connection.Execute(sql: query, transaction: txn);
                    //                    query = @"UPDATE SaleOrderItem SET IsPaymentApprovedForDelivery = (SELECT isService FROM JobCard WHERE JobCardId = " + jobcard.JobCardId + @")
                    //                                WHERE SaleOrderItemId = (SELECT SaleOrderItemId FROM JobCard WHERE JobCardId = " + jobcard.JobCardId + ")";
                    //                    connection.Execute(sql: query, transaction: txn);
                    int i = 0;
                    foreach (var item in jobcard.JobCardTask)
                    {
                        if (item.Existing == 1)
                        {
                            query = string.Empty;
                            query = @"insert  into JobCardTask(JobCardId,JobCardTaskMasterId,SlNo,EmployeeId,TaskDate,StartTime,EndTime,
                                      Hours,ActualHours,CreatedBy,CreatedDate,OrganizationId) Values 
                            (" + jobcard.JobCardId.ToString() + "," + item.JobCardTaskMasterId + "," + i.ToString() + "," + item.EmployeeId.ToString() + "," + item.TaskDate.ToString("dd/MMM/yyyy") + "," + item.StartTime + "," + item.EndTime + "," + item.ActualHours + "," + item.ActualHours + ",NULL,GETDATE(),NULL); SELECT CAST(SCOPE_IDENTITY() as int)";
                            connection.Query(query, transaction: txn);
                            i++;
                        }
                        else
                        {
                            query = string.Empty;
                            //query = "update JobCardTask set ActualHours = " + item.ActualHours.ToString() + " where JobCardId = " + jobcard.JobCardId.ToString() + ";";
                            //query = "update JobCardTask set ActualHours = " + item.ActualHours.ToString() + ",StartTime = " + item.StartTime.ToString() + ",EndTime = " + item.EndTime.ToString() + "  where SlNo = " + item.SlNo.ToString() + " and JobCardId = " + jobcard.JobCardId.ToString() + ";";
                            if (jobcard.isProjectBased == 0)
                            {
                                query = "update JobCardTask set ActualHours = " + item.ActualHours.ToString() + " where SlNo = " + item.SlNo.ToString() + " and JobCardId = " + jobcard.JobCardId.ToString() + ";";
                            }
                            else
                            {
                                query = "update JobCardTask set ActualHours = " + item.ActualHours.ToString() + " where JobCardTaskId = " + item.JobCardTaskId.ToString();
                            }
                            connection.Query(query, transaction: txn);
                        }
                    }
commit:
                    InsertLoginHistory(dataConnection, CreatedBy, "Update", "Job Card Completion", id.ToString(), "0");
                    txn.Commit();
                }
                catch (Exception)
                {
                    txn.Rollback();
                    throw;
                }
            }
            return(id);
        }