Пример #1
0
        /// <summary>
        /// Purpose is to create a client given a Client Code and Client Folder.
        /// </summary>
        /// <param name="clientCode">Unique Client Code</param>
        /// <param name="clientFolder">Unique Client Folder</param>
        /// <returns></returns>
        public DataValidatorReturn Create(string clientCode, string clientFolder)
        {
            DVR = MethodHelper.IsParameterEmpty("ClientCode", clientCode);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            DVR = MethodHelper.IsParameterEmpty("ClientFolder", clientFolder);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            if (Find(clientCode).ItemFound)
            {
                DVR.IsValid    = false;
                DVR.ReturnText = clientCode + " already exists.";
                DVR.ItemFound  = true;
                return(DVR);
            }

            if (FolderExists(clientFolder) == false)
            {
                DVR.IsValid    = false;
                DVR.ReturnText = clientFolder + " does not exist.";
                DVR.ItemFound  = true;
                return(DVR);
            }

            using (var context = new WorkOrderLogEntities())
            {
                Client client = new Client()
                {
                    ClientCode   = clientCode,
                    ClientFolder = clientFolder
                };

                try
                {
                    context.Clients.Add(client);
                    context.SaveChanges();
                    DVR.IsValid    = true;
                    DVR.ReturnText = "Client: " + clientCode + " Added to the Database.";
                    DVR.ReturnType = client;
                }
                catch (Exception exception)
                {
                    DVR.IsValid    = false;
                    DVR.ReturnText = exception.Message;
                }
            }

            return(DVR);
        }
Пример #2
0
        public DataValidatorReturn Delete(string clientCode)
        {
            DVR = MethodHelper.IsParameterEmpty("ClientCode", clientCode);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            DataValidatorReturn dvr = new DataValidatorReturn();

            dvr = Find(clientCode);

            if (dvr.ItemFound == false)
            {
                DVR.IsValid    = false;
                DVR.ReturnText = clientCode + " not found.";
                DVR.ItemFound  = false;
                return(DVR);
            }

            using (var context = new WorkOrderLogEntities())
            {
                try
                {
                    int workOrderHeaderCount = 0;

                    //Delete foreign relationships etc.
                    var workOrderHeaders = context.WorkOrderHeaders.Where(x => x.ClientCode == clientCode).ToList();
                    workOrderHeaderCount = workOrderHeaders.Count();

                    for (int i = 0; i < workOrderHeaderCount; i++)
                    {
                        WorkOrderHeader workOrderHeader = workOrderHeaders[i];
                        context.WorkOrderHeaders.Remove(workOrderHeader);
                    }

                    Client client = context.Clients.Where(x => x.ClientCode == clientCode).FirstOrDefault();

                    context.Clients.Remove(client);

                    context.SaveChanges();

                    DVR.IsValid    = true;
                    DVR.ReturnText = clientCode + " Removed Successfully." + Environment.NewLine + workOrderHeaderCount.ToString() +
                                     " Work Order Headers Removed successfully.";
                }
                catch (Exception exception)
                {
                    DVR.IsValid   = false;
                    DVR.ErrorText = exception.Message;
                }
            }

            return(DVR);
        }
Пример #3
0
        public DataValidatorReturn Create(int workOrderID, string clientCode)
        {
            DVR = MethodHelper.IsGreaterThanZero("Work Order Number", workOrderID);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            DVR = MethodHelper.IsParameterEmpty("Client Code", clientCode);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            if (Find(workOrderID).ItemFound)
            {
                DVR.IsValid    = false;
                DVR.ReturnText = "Work Order # " + workOrderID.ToString() + " already exists.";
                DVR.ItemFound  = true;
                return(DVR);
            }

            using (var context = new WorkOrderLogEntities())
            {
                WorkOrderHeader workderOrderHeader = new WorkOrderHeader()
                {
                    WOHdrID     = workOrderID,
                    ClientCode  = clientCode,
                    CreatedDate = DateTime.Now.ToLocalTime(),
                    CreatedBy   = "SYSTEM"
                };

                try
                {
                    context.WorkOrderHeaders.Add(workderOrderHeader);
                    context.SaveChanges();
                    DVR.IsValid    = true;
                    DVR.ReturnText = "Work Order #" + workOrderID.ToString() + " Added to the Database.";
                    DVR.ReturnType = workderOrderHeader;
                }
                catch (Exception exception)
                {
                    DVR.IsValid    = false;
                    DVR.ReturnText = exception.Message;
                }
            }

            return(DVR);
        }
Пример #4
0
        public DataValidatorReturn Create(string activityDescription, int activityTypeID)
        {
            DVR = MethodHelper.IsParameterEmpty("Activity", activityDescription);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            if (Find(activityDescription).ItemFound)
            {
                DVR.IsValid    = false;
                DVR.ReturnText = activityDescription + " already exists.";
                DVR.ItemFound  = true;
                return(DVR);
            }

            BO_ActivityType bO_ActivityType = new BO_ActivityType();

            DVR = bO_ActivityType.Find(activityTypeID);

            if (DVR.ItemFound == false)
            {
                return(DVR);
            }

            using (var context = new WorkOrderLogEntities())
            {
                Activity activity = new Activity()
                {
                    ActivityDescription = activityDescription,
                    ActivityTypeID      = activityTypeID
                };

                try
                {
                    context.Activities.Add(activity);
                    context.SaveChanges();
                    DVR.IsValid    = true;
                    DVR.ReturnText = "Activity: " + activityDescription + " Added to the Database.";
                    DVR.ReturnType = activity;
                }
                catch (Exception exception)
                {
                    DVR.IsValid    = false;
                    DVR.ReturnText = exception.Message;
                }
            }

            return(DVR);
        }
Пример #5
0
        /// <summary>
        /// Purpose is to create a client given a Client Code and Client Folder.
        /// </summary>
        /// <param name="clientCode">Unique Client Code</param>
        /// <param name="clientFolder">Unique Client Folder</param>
        /// <returns></returns>
        public DataValidatorReturn Create(string activityTypeShortDesc, string activityTypeLongDesc)
        {
            DVR = MethodHelper.IsParameterEmpty("Activity Type", activityTypeShortDesc);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            DVR = MethodHelper.IsParameterEmpty("Activity Type Description", activityTypeLongDesc);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            if (Find(activityTypeShortDesc).ItemFound)
            {
                DVR.IsValid    = false;
                DVR.ReturnText = activityTypeShortDesc + " already exists.";
                DVR.ItemFound  = true;
                return(DVR);
            }

            using (var context = new WorkOrderLogEntities())
            {
                ActivityType activityType = new ActivityType()
                {
                    ShortDescription = activityTypeShortDesc,
                    LongDescription  = activityTypeLongDesc
                };

                try
                {
                    context.ActivityTypes.Add(activityType);
                    context.SaveChanges();
                    DVR.IsValid    = true;
                    DVR.ReturnText = "Activity Type: " + activityTypeShortDesc + " Added to the Database.";
                    DVR.ReturnType = activityType;
                }
                catch (Exception exception)
                {
                    DVR.IsValid    = false;
                    DVR.ReturnText = exception.Message;
                }
            }

            return(DVR);
        }
Пример #6
0
        public DataValidatorReturn Delete(int activityTypeID)
        {
            DVR = MethodHelper.IsGreaterThanZero("Activity Type", activityTypeID);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            DataValidatorReturn dvr = new DataValidatorReturn();

            dvr = Find(activityTypeID);

            if (dvr.ItemFound == false)
            {
                DVR.IsValid    = false;
                DVR.ReturnText = activityTypeID + " not found.";
                DVR.ItemFound  = false;
                return(DVR);
            }

            using (var context = new WorkOrderLogEntities())
            {
                try
                {
                    int numWorkOrderDetails = 0;
                    int numActivities       = 0;
                    int currentActivityId   = 0;

                    //Delete foreign relationships etc.

                    //Get the activities.
                    var activities = context.Activities.Where(x => x.ActivityTypeID == activityTypeID).ToList();

                    if (activities.Any())
                    {
                        numActivities = activities.Count();

                        for (int i = 0; i < numActivities; i++)
                        {
                            currentActivityId = activities[i].ActivityID;

                            List <WorkOrderDetail> workOrderDetails = context.WorkOrderDetails.Where(x => x.ActivityID == currentActivityId).ToList();

                            if (workOrderDetails.Any())
                            {
                                numWorkOrderDetails = workOrderDetails.Count();
                                for (int j = 0; j < numWorkOrderDetails; j++)
                                {
                                    WorkOrderDetail workOrderDetail = workOrderDetails[j];
                                    context.WorkOrderDetails.Remove(workOrderDetail);
                                }
                            }

                            Activity activity = activities[i];
                            context.Activities.Remove(activity);
                        }
                    }

                    ActivityType activityType = context.ActivityTypes.Where(x => x.ActivityTypeID == activityTypeID).FirstOrDefault();

                    context.ActivityTypes.Remove(activityType);

                    context.SaveChanges();

                    DVR.IsValid    = true;
                    DVR.ReturnText = activityType.ShortDescription + " Removed Successfully." + Environment.NewLine + numActivities.ToString() +
                                     " Activities Removed successfully." + Environment.NewLine +
                                     numWorkOrderDetails + " Removed Successfully.";
                }
                catch (Exception exception)
                {
                    DVR.IsValid   = false;
                    DVR.ErrorText = exception.Message;
                }
            }

            return(DVR);
        }
Пример #7
0
        public DataValidatorReturn Create(int workOrderID, int itemNumber, int activityID)
        {
            WorkOrderHeader workOrderHeader = null;

            DVR = MethodHelper.IsGreaterThanZero("Work Order Number", workOrderID);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            DVR = MethodHelper.IsGreaterThanZero("Item Number", itemNumber);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            DVR = MethodHelper.IsGreaterThanZero("Activity ID", activityID);

            if (DVR.IsValid == false)
            {
                return(DVR);
            }

            if (Find(workOrderID, itemNumber, activityID).ItemFound)
            {
                DVR.IsValid    = false;
                DVR.ReturnText = "Work Order Detail # " + workOrderID.ToString() + " already exists.";
                DVR.ItemFound  = true;
                return(DVR);
            }

            BO_WorkOrderHeader bo_WorkOrderHeader = new BO_WorkOrderHeader();

            DVR = bo_WorkOrderHeader.Find(workOrderID);

            if (DVR.ItemFound == false)
            {
                DVR.IsValid    = false;
                DVR.ReturnText = "Work Order Header # " + workOrderID.ToString() + " doesn't exist.";
                DVR.ItemFound  = true;
                return(DVR);
            }
            else
            {
                workOrderHeader = DVR.ReturnType as WorkOrderHeader;
            }

            using (var context = new WorkOrderLogEntities())
            {
                // Find the work Order Header here.


                WorkOrderDetail workOrderDetail = new WorkOrderDetail()
                {
                    WOHdrID    = workOrderID,
                    ItemNumber = itemNumber,
                    ActivityID = activityID
                };

                try
                {
                    int activityTypeID = 2;

                    context.WorkOrderDetails.Add(workOrderDetail);

                    context.SaveChanges();

                    //Once we have created a work order detail need to look for the
                    //Activity using the activity Id, and then get the activityTypeId
                    //Go to the sourcescripthdr table and get the sourcescripthdrid
                    //and use the info from the sourcescriptdtl table to create
                    //WorkOrderDtlScript records also need to create these actual files
                    //by retrieving the source items and pasting to the new files.
                    BO_SourceScriptHdr  bo_SourceScriptHdr  = new BO_SourceScriptHdr();
                    DataValidatorReturn dataValidatorReturn = bo_SourceScriptHdr.Find(activityTypeID);

                    if (dataValidatorReturn.ItemFound)
                    {
                        var sourceScriptHdr  = dataValidatorReturn.ReturnType as SourceScriptHdr;
                        var sourceScriptDtls = sourceScriptHdr.SourceScriptDtls;

                        if (sourceScriptDtls.Any())
                        {
                            string sourceFileFullPath = string.Empty;
                            string sourceFile         = string.Empty;
                            string sourceClientCode   = string.Empty;
                            string destFile           = string.Empty;
                            string destClientCode     = string.Empty;
                            string destFileFullPath   = string.Empty;
                            string destFolder         = string.Empty;
                            string sourceFileContents = string.Empty;
                            string destFileContents   = string.Empty;

                            foreach (SourceScriptDtl sourceScriptDtl in sourceScriptDtls)
                            {
                                // Set the source File.
                                sourceFile         = sourceScriptDtl.SourceFile;
                                sourceClientCode   = sourceScriptDtl.ClientCode;
                                sourceFileFullPath = Path.Combine(sourceScriptDtl.Client.ClientFolder, sourceScriptDtl.SourceFile);

                                destClientCode   = workOrderHeader.ClientCode;
                                destFile         = sourceFile.Replace(sourceClientCode, destClientCode);
                                destFolder       = workOrderHeader.Client.ClientFolder;
                                destFileFullPath = Path.Combine(destFolder, destFile);

                                // Logic change instead of copying, replace text required
                                sourceFileContents = File.ReadAllText(sourceFileFullPath);
                                destFileContents   = sourceFileContents.Replace(sourceClientCode, destClientCode);
                                destFileContents   = destFileContents.Replace("0", workOrderHeader.WOHdrID.ToString());

                                File.WriteAllText(destFileFullPath, destFileContents);

                                //Create WorkOrderDetailScripts foreach script created.
                                BO_WorkOrderDtlScripts bo_WorkOrderDtlScripts = new BO_WorkOrderDtlScripts();
                                bo_WorkOrderDtlScripts.Create(workOrderDetail.WODtlId, destFile);
                            }

                            context.SaveChanges();
                        }
                    }


                    DVR.IsValid    = true;
                    DVR.ReturnText = "Work Order Detail #" + workOrderID.ToString() + " Added to the Database.";
                    DVR.ReturnType = workOrderDetail;
                }
                catch (Exception exception)
                {
                    DVR.IsValid    = false;
                    DVR.ReturnText = exception.Message;
                }
            }

            return(DVR);
        }